Reputation:

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

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

Upvotes: 2

Views: 4860

Answers (3)

user36457
user36457

Reputation:

If you mean binary to ASCII 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";

output:

Test

Upvotes: 8

Chas. Owens
Chas. Owens

Reputation: 64909

chr(0x41) or chr(65) turns the number 65 (41 in hex) into the letter "A", is this what you are looking for?

Upvotes: 1

ysth
ysth

Reputation: 98388

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

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

Upvotes: 0

Related Questions