LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to convert binary number to text/ascii? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-convert-binary-number-to-text-ascii-869045/)

peterson.julia 03-16-2011 06:16 PM

How to convert binary number to text/ascii?
 
Hi,
is there command in linux which is able to convert binary (0101001010000100) to text like it means something?

Thx

pljvaldez 03-16-2011 06:41 PM

bc ibase=2 0101001010000100 should do the trick.

EDIT: I found another article that says you need to use echo and pipe to bc like this
Code:

echo 'ibase=2;obase=A;0101001010000100' | bc
EDIT2: If you want to use wcalc, just do
Code:

wcalc 0b0101001010000100
The "0b" at the beginning means it is a binary input.

corp769 03-16-2011 06:57 PM

I noticed those examples convert over, but not to the actual ASCII characters; ie 01110100011001010111001101110100 to test. Is there anyway to do that?

peterson.julia 03-16-2011 11:38 PM

Quote:

Originally Posted by corp769 (Post 4293152)
I noticed those examples convert over, but not to the actual ASCII characters; ie 01110100011001010111001101110100 to test. Is there anyway to do that?

Exactly to convert ti to actual ASCII...

Kenhelm 03-16-2011 11:45 PM

Try
Code:

bin='01110100011001010111001101110100'
printf $(echo "obase=16;ibase=2;$bin" | bc | sed 's/../\\x&/g')

test

EDIT
Any non-printing characters can be converted to a dot or deleted using tr
Code:

printf $(echo "obase=16;ibase=2;$bin" | bc | sed 's/../\\x&/g') | tr -c '[:print:]' '.'


All times are GMT -5. The time now is 05:22 PM.