# Convert Binary to Text [duplicate]

Your task is to write a program, which takes a binary input and converts it to plain text. For Example:

01100001 01100010 01100011 = "abc"


## Rules

• Input can come from STDIN, function arguments, command line argument, file, whatever suits you.
• The program can be a function, full program, whatever works, really, as long as no external uncounted code/arguments are needed to run it.
• You can assume that the input is valid.
• The length of the input is not limited
• You can assume that all blocks are seperated with whitespaces

## Test Cases

01010100 01100101 01110011 01110100 = "Test"
01001000 01100101 01101100 01101100 01101111 = "Hello"
01010111 01101111 01110010 01101100 01100100 00001101 00001010 = "World"
01000101 01111000 01100001 01101101 01110000 01101100 01100101 00001101 00001010 = "Example"
01100010 01101001 01101110 00001101 00001010 = "bin"


This is , so the shortest solution wins.

## marked as duplicate by Okx, manatwork code-golf StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Mar 29 '17 at 10:54

• Do mean we can or we must assume that all blocks are separated with whitespaces? – Dada Mar 29 '17 at 9:26
• @Dada you can – Tom291 Mar 29 '17 at 9:27
• Why does this look related to the binary heart challenge? Most answer there is just a text to binary converter. – Matthew Roh Mar 29 '17 at 10:22
• What input formats are allowed? For example, an 8-column matrix of zeros and ones? A 2D array of chars? – Luis Mendo Mar 29 '17 at 10:25
• Why is the dc answer accepted at all? The 05AB1E answer was first. – Okx Mar 29 '17 at 11:22

# 05AB1E, 4 bytes

#CçJ


Uses the CP-1252 encoding. Try it online!

# dc, 4 bytes

Needs as input the binary blocks with no separator. This is allowed by the OP.

2i?P


Try it online!

Explanation: using the "abc" example as test case

• 2i? sets 2 as input radix, then reads the line (output radix is 10 by default). This converts the binary input to decimal: 011000010110001001100011 -> 6382179.
• P is a special printing mode that assumes a base 256 number, using its "digits" as ASCII codes: 6382179 = (97 * 256 2) + (98 * 256 1) + (99 * 256 0) -> abc

# Perl 5, 15 bytes

14 bytes of code + -p flag.
The input must be supplied without final newline (with echo -n for instance).

$_=pack"B*",$_


Try it online!

## JavaScript (ES6), 52 bytes

s=>String.fromCharCode(...s.split .map(s=>0b+s))


## sed and dc, 23, 19 bytes

sed 's/.*/2i&P/'|dc

• Why not just 's/.*/2i&P/'? – Neil Mar 29 '17 at 11:57
• @Neil: good point – Thor Mar 30 '17 at 11:33

# Pyth, 7 Bytes

smCid2c


Takes input as string.

Try it!

û{$-2Bo}r.  # Explained û # Split the implicit input by Spaces. { }r # Replace each element in a list based on a function.$-2B     # Convert from Base 2
o    # Get the ordinal of the character.
. # Concatenate the list.


Try it online!

## CJam, 10 bytes

l:~8/2fb:c


Try it online!

### Explanation

l    e# Read input.
:~   e# Evaluate each character, resulting in a flat list of bits.
8/   e# Split into chunks of 8 bits.
2fb  e# Convert each from binary to an integer.
:c   e# Convert each integer to a character.


## Mathematica, 50 bytes

FromCharacterCode[#~FromDigits~2&/@StringSplit@#]&


# Röda, 36 35 bytes

{split|chr parseInteger(_,radix=2)}


Try it online!

This is an anonymous function that reads the input from the stream and prints the result.

It uses three builtins:

• split splits the input at whitespaces
• parseInteger converts a binary string to an integer value
• chr converts an integer to a Unicode character

# Gema, 33 characters

<D><s>=@int-char{@radix{2;10;$1}}  Sample run: bash-4.3$ gema '<D><s>=@int-char{@radix{2;10;$1}}' <<< '01010000 01010000 01000011 01000111' PPCG  ## Gema, 31 characters Using no delimiter in the input. <D8>=@int-char{@radix{2;10;$1}}


Sample run:

bash-4.3$gema '<D8>=@int-char{@radix{2;10;$1}}' <<< '01010000010100000100001101000111'
PPCG


## Python 2, 49 bytes

Try it online

lambda S:''.join(chr(int(c,2))for c in S.split())

• Do you need the '0b'+ as well as the ,2? – Neil Mar 29 '17 at 9:21
• @Neil Yes, chr() accepts only [0-255] integers and binary in python represented like 0bxxxxxx. So first I need to add 0b to binary blocks and then convert them into basic int to get chars. While converting, I need to specify base of input - 2. – Dead Possum Mar 29 '17 at 9:24
• @ovs Oh, thats true! Unintuitive :) – Dead Possum Mar 29 '17 at 9:28
• You can save 3 bytes by using list comprehension! Try it online! – Keerthana Prabhakaran Mar 29 '17 at 9:49
• @KeerthanaPrabhakaran Good one! I've saved even more. Thanks – Dead Possum Mar 29 '17 at 9:56

# Ruby, 36 characters

->b{b.gsub(/\d+ ?/){$&.to_i(2).chr}}  Sample run: irb(main):001:0> ->b{b.gsub(/\d+ ?/){$&.to_i(2).chr}}['01010000 01010000 01000011 01000111']
=> "PPCG"


C, 106 Bytes

main(a,b,c,d,e,f)char**b,*f;{for(c=1;c<a;c++){for(f=b[c],e=7,d=0;*f;f++,e--)d+=(*f-48)*1<<e;putchar(d);}}


## PHP <5.3, 53 Bytes

Idea by @manatwork

foreach(split(" ",$argv[1])as$v)echo chr(bindec($v));  # PHP, 55 Bytes I prefer cause it can work without spaces foreach(str_split($argv[1],9)as$v)echo chr(bindec($v));


without spaces change 9 to 8 for 7 bits 7

foreach(explode(" ",$argv[1])as$v)echo chr(bindec($v));  ## PHP >=7, 62 Bytes <?=join(($a=array_map)(chr,$a(bindec,explode(" ",$argv[1]))));

• Is this PHP 7? Can't make it work due to a syntax error. – manatwork Mar 29 '17 at 10:22
• Yes, but before you were able to use the deprecated split() function, so the length would be the same. – manatwork Mar 29 '17 at 10:51
• Uhm, I also tried str_split(), but is the same length as explode(). And both are 2 characters longer than split(). [insert confused smiley here] – manatwork Mar 29 '17 at 11:17
• @manatwork I think I was the only confused one. I like it not make post with deprecated functions. I mean str_split in combine with the foreach loop is the best solution cause it can handle other inputs with little changes – Jörg Hülsermann Mar 29 '17 at 11:30

## Jelly, unfinished

I still haven't figure out how to repeat for every line in STDIN, or get amount of lines in STDIN in Jelly. So far though, I came up for a solution for a single line/character.

ɠO_48ḄỌ


Any help is appreciated!