I'm sure this is going to be really basic, but I've gone several decades using Perl and never needed the pack or unpack functions before.
#!/usr/bin/perl use strict; use warnings; # my $pReqsca = "ABCD"; my @bytary = unpack 'C*', $pReqsca; + my $binstr = ''; + foreach my $scabyt (@bytary) { + my $intbyt = int($scabyt); + my $hexbyt = sprintf("%02X", $intbyt); + my $binbyt = unpack 'b8', $scabyt; + $binstr .= $binbyt; + print " Byte = [$scabyt] Integer = [$intbyt] Hex = [$hexbyt] B +inary = [$binbyt] Binary String = [$binstr]\n"; print "Aborting Loop\n"; last; }
Results:
W:\Steve\PerlMonks>perl sopw-584100.pl Byte = [65] Integer = [65] Hex = [41] Binary = [01101100] Binary + String = [01101100] Aborting Loop
Same results using 'B8',
Last time I checked, Hex 41 should show binary 01000001.
What am I missing here?
In reply to unpack Binary FAIL by marinersk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |