g | x | w | all
Bytes Lang Time Link
048AWK241104T174017Zxrs
073BrainChild241104T035931ZATaco
002Japt230813T082925ZShaggy
078brainfuck241103T192457Znoodle p
039YASEPL240207T203922Zmadeforl
081Binary Lambda Calculus 81 bits = 10.125 bytes240412T125922ZLegendar
004Uiua240306T165821Znoodle p
022Kotlin240310T101707ZCactusro
048Swift 5.9240306T204114ZmacOSist
025Scala 3240306T173448Zmovatica
046Thue230901T005749ZMegaTom
042BrainFlak230901T004716ZMegaTom
058C clang230811T173234Zcorvus_1
020Ruby230812T174621Zkait0u
024Julia 1.0230816T152740ZAshlin H
053brainfuck230815T200012Zfwoosh
028PowerShell230815T144606ZJames Fl
017dc230814T161450ZDigital
028sed 4.2.2230814T154002ZDigital
010x86+MMX machine code230812T211907ZPeter Co
033Lua230812T134614Zval - di
022R230811T212215ZDominic
015Perl 5230812T113035ZKjetil S
026Haskell230811T210136Zxnor
015TIBasic230811T234118ZYouserna
079TypeScript Type System230811T230743Zemanresu
018///230811T224118Zemanresu
003Husk230811T205751ZDominic
00305AB1E230811T194318ZKevin Cr
045J230811T202358Zsouth
032PHP230811T201824ZSamuel C
003MathGolf230811T200116ZKevin Cr
016Retina 0.8.2230811T194127ZNeil
023Arturo230811T191419Zchunes
003Charcoal230811T173422ZNeil
128TypeScript's Type System230811T163219Znoodle p
021JavaScript Node.js230811T161754Zl4m2
020Excel230811T165730ZJos Wool
014Mathematica230811T163358ZMichael
021Python 3230811T162005ZThe Thon
002Vyxal230811T161621ZThe Thon
002Thunno 2230811T161134ZThe Thon
003APL Dyalog Extended230811T160808ZAdá

AWK, 48 bytes

{gsub(1,"0*");while(sub(/*0/,"0**"));gsub(0,X)}1

Try it online!

Another version:

{for(;i++<=NF;)for(k=1;$i&&k++<=2^(NF-i);)printf "*"}

BrainChild, 73 bytes

include*;int j=0;gets()(function(int c)j=j*2+(c-48))while(j--)putchar(65)

Readable

include io.bc;
int j=0;
gets()(function(int c){
    j=j*2;
    j=j+(c-48)
})
while(j--)
    putchar('A')

Try It Online!

Japt, 2 bytes

Takes input as a binary string, outputs a string of spaces.

Íç

Try it (Footer replaces spaces with 1s)

Íç     :Implicit input of binary string
Í      :Convert to decimal
 ç     :Repeat a space that many times

brainfuck, 78 bytes

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

Attempt This Online!

Someone already did it in brainfuck and got a better score here, but I thought I'd try it out myself.

YASEPL, 65 61 49 47 45 41 39 bytes

=i=1'=l®1+`1--!a¥i,1=r$2^l*a;a,r~!+!l+[

1 is the unary digit, prompts you for input

YASEPL, 37 35 bytes

this one exits with an error but works the same.

=i=1'=l®1-i-!a¥i,1=r$2^l*a;a,r~!+?6

Binary Lambda Calculus: 81 bits = 10.125 bytes

Lambda calculus has no standard encoding for binary numbers. I chose the conversion from my favorite base 2 encoding to unary Church numerals.

Mogensen's general encoding for arbitrary base b is defined by

$$ \langle n\rangle_b=\lambda^{S(b)}(d_0\circ\dots\circ d_{\lfloor\log_b(n)\rfloor}\ b) $$ $$ \text{where de Bruijn index }\ d_i=\frac{n}{b^i}\pmod{b} $$

E.g. $$\langle6\rangle_2=\lambda^3(0\ (1\ (1\ 2)))$$

Conversion from b=2 to Church numerals follows by applying $$(\langle n\rangle_2\ \langle0\rangle_u\ (\mathrm{succ}_u\circ(\mathrm{mult}_u\ \langle2\rangle_u))\ (\mathrm{mult}_u\ \langle2\rangle_u))$$

Which golfs down to a function of 81 bits length:

000101011000001000000001110010111101100101111011010000000010111101100101111011010

I wasn't able to share the two curried multiplication functions completely since additional abstractions/indices actually increased the size. Maybe someone else here has some better ideas?

Trying-to-be-clever 84 bit alternative:

000100010101110000010000000011100101011111011101101010000000010111101100101111011010

Uiua, 6 4 bytes

⊚°⋯⇌

Try it

Convert from binary, use where to change this to an array of N 0s.

Before I knew about °⋯:

Uiua, 13 bytes

×0⇡/+×ⁿ:2⇌⇡⧻.

Try it

Multiply by powers of 2, sum, range, multiply each by 0.

Kotlin, 22 bytes

{"*".repeat(toInt(2))}

Try it online!

Swift 5.9, 48 bytes

let f={{String.init}()("*",Int($0+"",radix:2)!)}

Scala 3, 25 bytes

"*"*Integer.parseInt(_,2)

Attempt This Online!

Thue, 46 bytes

a::=:::
1::=0*
*0::=0**
*>::=!>
!::=~*
::=
a>

Try it online!

Brain-Flak, 42 bytes

([]){{}({}<>({}){})<>([])}<>{({}[(())])}{}

Try it online!

The code works by accumulating the values of partial sums on the second stack, then it expands the second stack from the single value n, to n copies of 1.

([]) Push the stack height
{ While the stack is not empty
  {} pop the stack height
  (
    {} pop the top of the stack
    <> Jump to the second stack
    ({}){} Add the top element of the second stack twice, popping it
  ) Push the sum
  <> 
  ([]) Push new height
}
<> On the second stack:
{ While n>0
  ({} Pop n
    [(()) Push 1
    ] add -1
  ) Push n-1
}{} Pop the zero

C (clang), 60 58 bytes

i;f(char*s){for(i=0;*++s;i+=i+*s-48);i&&printf("%0*d",i);}

Attempt This Online!

Ruby, 20 bytes

->(b){?**b.to_i(2)} 

Try it online!

It goes from binary to a decimal integer, and becomes a factor by which an asterisk char is multiplied.

(Idea to switch to char from string was suggested by Travis. Thanks!)


Ruby, 21 bytes | (old)

->(b){"*"*b.to_i(2)} 

Try it online!

Same as the upper one, but the upper one has been improved.

Julia 1.0, 24 bytes

~x="*"^parse(Int,"0b"*x)

Try it online!

Generally, any base other than 10 needs to be specified: parse(Int,x,base=2). Two bytes are saved by appending a 0b integer prefix instead.

brainfuck, 53 bytes

Takes a string of 0 and 1 characters, outputs a string of 1s.

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

Explaination

>,[                 read a character
>-[<->-----]<+++    subtract 48 to turn it into 0/1
<[->++<]            double the existing sum and add it to the new digit
>>,]                read another character and repeat if not EOF
>-[<+>-----]<--     make 49
<[->.<]             print 49 the necessary number of times

Try it online!

PowerShell, 28 bytes

"*"*[Convert]::ToInt32($_,2)

Try it online!

dc, 17

[q]sz2iA?^9/d0=zn

Try it online!

Explanation

[ ]                # define a macro to...
 q                 #   quit (i.e. print the empty string)
   sz              # save the macro to register z
     2i            # set input radix to 2 (binary)
       A           # pop 10
        ?          # read input
         ^         # exponentiate 10 to the power of the input
          9/       # divide by 9.  This gives a number consisting of n 1s, or 0
            d      # duplicate top of stack
             0=z   # if equal to 0, call macro stored in z register to print the empty string
                n  # otherwise print the unary number

sed 4.2.2, 28

:
s/1/0u/
s/u0/0uu/
t
s/0//g

Implementation algorithm as per the question.

Try it online!

x86+MMX machine code, 10 bytes

Despite the question only saying the input has to be "binary", comments seem to imply they're thinking of a text string of base-2 digits, not 1-bit digits packed into an integer which a computer can already use directly as an unsigned integer. If that's allowed, see my 7-byte answer on Output / Convert to unary number.

This is that answer plus conversion from 8 bytes to an 8-bit integer, by extracting the high bit of each input. Input is in mm0, an MMX vector register, with the lowest element being the least significant. (If stored to memory, this would be opposite of standard printing order where the most significant goes first, at the lowest address of a string.)

   ; machine code    |   NASM source
                       ; RDI or ES:EDI = output buffer of size n+1
                       binary_to_unary:
                       ;  pslld    mm0, 7     ; 4 bytes. For input digits '0' / '1', shift the low bit to high
  0FD7C8                pmovmskb ecx, mm0    ; pack the binary digits into an integer in ECX
                                             ; memset(dst, '1', n)
  B031                  mov      al, '1'
  F3AA                  rep stosb
  880F                  mov byte [rdi], cl   ; terminate the C-style string
  C3                    ret

For ASCII '0' / '1' input, we'd start with pslld mm0, 7 to shift the low bit to the high position of each byte. Also, if the digit-string was loaded from a string in memory in printing order (most significant at lowest address), we'd need to byte-reverse. In that case scalar code to read input would be smaller than movbe or load+bswap in an integer register + movq mm0, rax, or psufb with an 8-byte vector constant.

In this current version, our input string in an MMX register is effectively big-endian, most significant digit in the highest element number (on the left when writing it in the notation Intel manuals use to document vector instructions).

x86 scalar machine code, 14 bytes, input from a C string in printing order

Callable from C with the x86-64 System V calling convention as void binary_string_to_unary(const char *binary_src, char *unary_dst);. Use the x32 ABI for 32-bit pointers, or change the mov edi, esi to push rsi/pop rdi to copy a 64-bit register with the same code size. (Or use the same binary machine code in 32-bit mode.)

               binary_string_to_unary:
  B030           mov      al, '0'    ; input digit to compare against, also the output digit
               .loop:
  11C9           adc    ecx, ecx     ; ECX = 2*ECX + CF
  AE             scasb               ; set FLAGS like cmp al, [rdi] then increment RDI.   CF=1 for digit='1', CF=0 for digit='0'.
  76FB           jbe   .loop         ; while('0' <= digit);   i.e. while digit >= '0', false for digit = 0 terminator

  89F7           mov   edi, esi      ; x32 ABI, or for 32-bit mode.  For full 64-bit pointers, push rsi / pop rdi 
  F3AA           rep stosb           ; memset(rdi, al='0', rcx)
  880F           mov   [rdi], cl     ; terminate the C-style string
  C3             ret

Note that we don't xor ecx,ecx before the loop. Instead we rely on the input string being '0'-padded to at least 32 digits, so the previous contents get shifted out.

There might be a way (with same code size) to take the input pointer in RSI like you'd expect from the traditional meanings of those registers, perhaps with lodsb / cmp al, '0' (3 bytes instead of 1 for scasb, but avoiding the 2-byte mov edi, esi after the loop). Change the branch conditions accordingly for comparing in the other direction. Except that would get CF=0 for digit='1'. So maybe add al, 255-'0' so '1' produces a carry-out but '0' doesn't? And the terminator is a value that results in some FLAGS condition that the other two don't, perhaps a signed overflow and/or the sign flag.

Lua, 33 bytes

print(('*'):rep(tonumber(...,2)))

Try it online!

R, 22 bytes

\(x)rep(1,strtoi(x,2))

Attempt This Online!

Convert from binary and repeat 1 that many times.

Unfortunately shorter than the more-interesting (I think):

R, 36 34 bytes

Edit: -2 bytes thanks to pajonk

\(x)Reduce(\(a,b)c(a,a,b[b]),x,{})

Attempt This Online!

Input is a vector of binary digits; fold over (Reduce) this from the left, starting with an empty vector (NULL), at each step duplicating whatever we've got so far, and appending the new digit if it's a 1.

Perl 5, 15 bytes

$_=9x oct"0b$_"

Try it online!

Outputs 9 (my chosen char) the number of times given in the input binary number.

Haskell, 26 bytes

f l=10^foldl((+).(2*))0l-1

Try it online!

Input is a list of 0/1, output is a number like 9999999999 made of the digit 9.

Haskell is interesting for this challenge because it lacks base-conversion built-ins without imports, so we have to do it ourselves. This answer folds the operation \n b->n*2+b over the list of bits to get a number k, then computes 10^k-1 to get a number made of k 9-digits. The 9's trick is shorter than more natural methods like replicate k 1 or 1<$[1..k] or take k[0,0..].

It's slightly longer to do the power-of-10 within the fold and decrement after:

27 bytes

pred.foldl(\n b->n^2*10^b)1

Try it online!

though if we bend the rules and represent bits as 1 or decimal 10, we can do

21 bytes

pred.foldl((*).(^2))1

Try it online!

Haskell, 26 bytes

foldl(\s b->s++s++[1|b])[]

Try it online!

Input is list of Booleans, output is a list of 1's. This iterates over the list of Booleans, each time doubling the current string then appending an additional 1 if the bit is True.

TI-Basic, 15 bytes

1 or rand(.5sum(Ans2^cumSum(1 or Ans

Input is taken as a list of 0s and 1s in little-endian binary in Ans. Output is a list of 1s.

TypeScript Type System, 79 bytes

type B<S>=S extends`${infer Q}${infer V}`?`${B<V>}${B<V>}${Q extends"1"?Q:""}`:S

Try it on the Typescript Playground!

Note: This works with little-endian binary, not big-endian.

While the algorithm in the post allows simply performing replacements, we can take advantage of Typescript's ability to anchor string matches for a much simpler algorithm.

Essentially, S extends`${infer Q}${infer V}` matches the first character Q and the rest of the string V. We recurse on V twice, and append a 1 if Q is a 1.

///, 18 bytes

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

Try it online!

I didn't write this, I borrowed it from the esolangs wiki. Here's how it works:

Let's start with the string 10101, which represents 21.

/1/0*/ replaces 1s with 0*. The string becomes 0*00*00*. In this, each * represents a sort of place value - for example, the first * has 4 0s after it, so it represents 24 = 16.

/*0/0**/ replaces each * before a zero with two copies of it after the zero, each with half the place value. The first replacement this would do would be replacing 0*00*00* with 00**0*00*, replacing a * representing 16 with 2 *s each representing 8.

In ///, replacements are repeated until nothing is left to replace, so this will eventually result in a string with some amount of 0s at the start, followed by 21 *s each representing 1.

Finally, /0// removes the leading zeros, leaving just 21 *s, which is the output in unary.

Husk, 3 bytes

B1ḋ

Try it online!

  ḋ  # interpret input as binary digits
B    # and convert this to base
 1   # 1

05AB1E, 3 bytes

Since outputting the unary as a single character is required, there are a couple of 3 bytes alternatives:

If a mixture of multiple characters for the unary output would have been allowed, since only the length matters in unary, it could have been 2 bytes with:

C∍

Outputs a mixture of 1s and 0s (depending on the input) for its unary output.

Try it online or verify all test cases.

Explanation:

C   # Convert the (implicit) input binary-string to a base-10 integer
 ð× # Pop and push a string with that many spaces
    # (after which the result is output implicitly)
  
$   # Push 1 and the input binary-stringC×
Î   # Or alternatively, push 0 and the input binary-string
 C  # Convert the binary-string to a base-10 integer
  × # Repeat the 1 or 0 that many times as string
    # (after which the result is output implicitly)

C   # Convert the (implicit) input binary-string to a base-10 integer
 Å9 # Pop and push a list with that many 9s (or any other digit)
    # (after which the result is output implicitly)
C   # Convert the (implicit) input binary-string to a base-10 integer
 ∍  # Extend/shorten the (implicit) input binary-string to that length
    # (after which the result is output implicitly)

J, 4 or 5 bytes

#.##

Uses the length of the input digit list for the unary digit.

Attempt This Online!

Like 05AB1E, uniformity is one extra byte, with alternatives.

PHP, 32 bytes

echo str_repeat('*',bindec($i));

Where $i is the input string.

MathGolf, 3 bytes

Some different alternatives are available:

Explanation:

å    # Convert the (implicit) input binary-string to a base-10 integer
 ⌂*  # Repeat that many "*" as string
  *  # Or alternatively, repeat that many spaces as string
     # (after which the entire stack is output implicitly as result)

å    # Convert the (implicit) input binary-string to a base-10 integer
 Ä   # Pop and loop that many times, using the following character as inner code-block:
 {   # Or alternatively, use everything after it as code-block:
  ⌂  #  Push an "*" to the stack every iteration
     #  Or alternatively, push a space character to the stack every iteration
     # (after which the entire stack is joined together and output implicitly as result)

Retina 0.8.2, 16 bytes

1
01
+`10
011
0

Try it online! Link includes test cases. Explanation: A direct interpretation of the method given in the question, except using 1 instead of * for obvious reasons. Note that the method in Retina's own tutorial is slightly different preferring to use ^0+ presumably for a slight performance improvement.

Arturo, 23 bytes

$=>[@.of:from.binary&1]

Try it!

Returns a list of digits.

$=>[             ; a function where input is assigned to &
    from.binary& ; convert input from binary string to decimal integer
    @.of: _ 1    ; create list of that many 1s
]                ; end function

Charcoal, 3 bytes

⍘S²

Try it online! Link is to verbose version of code. Outputs a string of -s. Explanation:

 S  Input string
⍘   Convert from base
  ² Literal integer `2`
    Print as row of `-`s

Unfortunately BaseString(2, InputString()) performs a different operation, which means I can't use implicit input to save a byte.

TypeScript's Type System, 130 128 bytes

//@ts-ignore
type R<S,F,X>=S extends`${infer A}${F}${infer B}`?R<`${A}${X}${B}`,F,X>:S;type B<S>=R<R<R<S,1,"02">,20,"022">,0,"">

Try it at the TypeScript Playground!

Uses 2 as the unary digit. Defines a utility type to recursively remove all occurrences of a given string with a different string, and then defines the main type which is a series of nested calls to the utility type.

JavaScript (Node.js), 21 bytes

x=>'x'.repeat('0b'+x)

Try it online!

Excel, 20 bytes

=REPT(9,BIN2DEC(A1))

Input in cell A1.

Mathematica, 14 bytes

As a list of '1's:

Table[1,2^^#] &

Anonymous function. Would probably be 10 bytes in the hypothetical mthmca golfing language.

Python 3, 21 bytes

lambda s:"*"*int(s,2)

Try it online!

Vyxal, 2 bytes

BI

Try it Online! or see it with asterisks instead

Same as my Thunno 2 answer.

Explanation

BI  # Implicit input
B   # From binary
 I  # That many spaces
    # Implicit output

Thunno 2, 2 bytes

Ḃṣ

Try it online! or see it with asterisks instead

Uses spaces.

Explanation

Ḃṣ  # Implicit input
Ḃ   # From binary
 ṣ  # That many spaces
    # Implicit output

APL (Dyalog Extended), 3 bytes

Anonymous tacit prefix function. Takes list of binary digits and returns list of 1s

⊥⍴≡

Try it online!

 the base-2 evaluation

reshapes

 the depth (nesting level, which is always 1 for a list)