Skip to main content
added 283 characters in body
Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76

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 may use any reasonable input and output format, i.e. stringsshould take the binary number as a string (optionally with a separator), list, or equivalent structure of characters / digits, etc. You can useusing any digitsnumber or digit you like to representfor the binary anddigits. The unary numbersoutput 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 zeroeszero bits to a certain length.

One method you may use to achieve this task is documented at this esolangs.org article:

  1. Replace all 1s with 0* (Using * as the unary digit; you may use any character.)
  2. Replace all *0s with 0**.
  3. Remove all 0s.

ExamplesHere are some examples, using 0 and 1 for the binary digits and * for the unary digit:

  • 1001*********
  • 1010**********
  • 00111111***************************************************************
  • 00000 → (empty output)

This is , so the shortest answer in each language wins.

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 may use any reasonable input and output format, i.e. strings, list of characters / digits, etc. You can use any digits you like to represent the binary and unary numbers. 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 zeroes to a certain length.

One method you may use to achieve this task is documented at this esolangs.org article:

  1. Replace all 1s with 0* (Using * as the unary digit; you may use any character.)
  2. Replace all *0s with 0**.
  3. Remove all 0s.

Examples:

  • 1001*********
  • 1010**********
  • 00111111***************************************************************

This is , so the shortest answer in each language wins.

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:

  1. Replace all 1s with 0* (Using * as the unary digit; you may use any character.)
  2. Replace all *0s with 0**.
  3. 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 , so the shortest answer in each language wins.

Became Hot Network Question
Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76

Convert binary to unary

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 may use any reasonable input and output format, i.e. strings, list of characters / digits, etc. You can use any digits you like to represent the binary and unary numbers. 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 zeroes to a certain length.

One method you may use to achieve this task is documented at this esolangs.org article:

  1. Replace all 1s with 0* (Using * as the unary digit; you may use any character.)
  2. Replace all *0s with 0**.
  3. Remove all 0s.

Examples:

  • 1001*********
  • 1010**********
  • 00111111***************************************************************

This is , so the shortest answer in each language wins.