# Binary to unary conversion

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

### Python 3.0

```def binarytounary(bstring):
bstring = bstring.replace("1","0*")
while "*0" in bstring:
bstring=bstring.replace("*0","0**")
return bstring.replace("0","")
```

### ///

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

### Retina

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

### Sed

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