Skip to main content
Commonmark migration
Source Link

brainfuck, 50 bytes

>,[[->>>+<[-<+>>-]>[-<+>>]<<<<]+>>[-<<+>>]<]<[-.<]

Try it online! (with 10 as input)... Or try this naïve version with human-readable output, where I just added 48 + signs by hand, so that you guys can read the output.

How it works:

Reads the input and does the following, iteratively:

  • divide by 2, finding quotient and remainder
  • save the remainder + 1 on the left (this will make it easier to retrace the binary representation later)
  • move the tape right and repeat with this quotient as the new input

Then we walk left, printing the remainders, by first decreasing them by 1 to restore their real value.

brainfuck, 50 bytes

>,[[->>>+<[-<+>>-]>[-<+>>]<<<<]+>>[-<<+>>]<]<[-.<]

Try it online! (with 10 as input)... Or try this naïve version with human-readable output, where I just added 48 + signs by hand, so that you guys can read the output.

How it works:

Reads the input and does the following, iteratively:

  • divide by 2, finding quotient and remainder
  • save the remainder + 1 on the left (this will make it easier to retrace the binary representation later)
  • move the tape right and repeat with this quotient as the new input

Then we walk left, printing the remainders, by first decreasing them by 1 to restore their real value.

brainfuck, 50 bytes

>,[[->>>+<[-<+>>-]>[-<+>>]<<<<]+>>[-<<+>>]<]<[-.<]

Try it online! (with 10 as input)... Or try this naïve version with human-readable output, where I just added 48 + signs by hand, so that you guys can read the output.

How it works:

Reads the input and does the following, iteratively:

  • divide by 2, finding quotient and remainder
  • save the remainder + 1 on the left (this will make it easier to retrace the binary representation later)
  • move the tape right and repeat with this quotient as the new input

Then we walk left, printing the remainders, by first decreasing them by 1 to restore their real value.

Source Link
RGS
  • 14.1k
  • 1
  • 57
  • 116

brainfuck, 50 bytes

>,[[->>>+<[-<+>>-]>[-<+>>]<<<<]+>>[-<<+>>]<]<[-.<]

Try it online! (with 10 as input)... Or try this naïve version with human-readable output, where I just added 48 + signs by hand, so that you guys can read the output.

How it works:

Reads the input and does the following, iteratively:

  • divide by 2, finding quotient and remainder
  • save the remainder + 1 on the left (this will make it easier to retrace the binary representation later)
  • move the tape right and repeat with this quotient as the new input

Then we walk left, printing the remainders, by first decreasing them by 1 to restore their real value.