marinersk has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: unpack Binary FAIL
by ikegami (Patriarch) on Aug 08, 2025 at 02:35 UTC | |
by marinersk (Priest) on Aug 08, 2025 at 03:45 UTC | |
|
Re: unpack Binary FAIL
by ysth (Canon) on Aug 10, 2025 at 20:26 UTC |