How can I convert a binary number to a string character using a Perl script?

How can I convert a binary number to a string character using a Perl script?

+1


a source to share


3 answers


If you mean ASCII binary like this webpage, this should do the trick:

#!/usr/bin/perl

$binarySample = "01010100011001010111001101110100"; # "Test" in binary
$chars = length($binarySample);
@packArray = pack("B$chars",$binarySample);
print "@packArray\n";

      



exit:

Test
+7


a source


chr(0x41)

or chr(65)

converts the number 65 (41 in hex) to the letter "A" is that what you are looking for?



+1


a source


Strings can contain either binary data or text characters; nothing special is required.

Tell us more about what you are trying to do and it may shed some light on what you mean by "convert" or "binary".

0


a source







All Articles