The title says it all; Given a number in the binary (base-2) number system, output the same number expressed in unary (base-1).
You should take the binary number as a string (optionally with a separator), list, or equivalent structure of digits, using any number or digit you like for the digits. The unary output can use any aforementioned format, and it should use a single-digit throughout the number but does not have to be consistent for different input values. You may choose to assume that the binary number will have no more than 8 bits, and/or that it will always be left-padded with zero bits to a certain length.
One method you may use to achieve this task is documented at this esolangs.org article:
- Replace all
1s with0*(Using*as the unary digit; you may use any character.) - Replace all
*0s with0**. - Remove all
0s.
Here are some examples, using 0 and 1 for the binary digits and * for the unary digit:
1001→*********1010→**********00111111→***************************************************************00000→ (empty output)
This is code-golf, so the shortest answer in each language wins.
any reasonable input & output formatI'm guessing taking the input as an integer is not acceptable, but it would be good to state it explicitly. \$\endgroup\$unsignedint); that's a good way to store binary! \$\endgroup\$0000to result in an empty output? \$\endgroup\$