Binary to unary conversion

From Esolang
Jump to: navigation, search

A binary to unary conversion program is a program that can convert a given number in binary form to a unary form. It is mainly used to showcase Markov algorithm (wikipedia). Its steps are as follows:

  1. Replace all instances of 1 with 0* (* can be any character)
  2. Replace all instances of *0 with 0**
  3. Remove all instances of 0

For example, here is the conversion of 1001 to *********:

  1. 1001:
    1. 1001 -> 0*000*
  2. 0*000*:
    1. 0*000* -> 00**00*
    2. 00**00* -> 00*0**0*
    3. 00*0**0* -> 000***0***
    4. 000***0*** -> 000**0*****
    5. 000**0***** -> 000*0*******
    6. 000*0******* -> 0000*********
  3. 0000********* -> *********

Examples in programming languages

///

/1/0*//*0/0**//0//100010

Retina

1
0*
+`\*0
0**
0
(an extra line must be present)

Try it online.

Sed

s/1/0*/g;:x;s/\*0/0**/g;tx;s/0//g