in reply to Re^2: converting artibrary binary data to numeric values
in thread converting artibrary binary data to numeric values
Are you really, really sure that you get eight bytes from your file, the first having the value 0x0D and the second having the value 0x0E (and so on)?
If so, you might need to do some bit twiddling to combine all the nibbles:
use Data::Dumper; my $str = "\x0D\x0E\x0A\x0D\x0B\x0E\x0E\x0F"; my @bytes = unpack 'C8', $str; print Dumper \@bytes; # Now add up the byte-pairs for (0..3) { $bytes[ $_ ] = $bytes[ $_*2 ] * 16 + $bytes[ $_*2 +1 ]; }; splice @bytes, 4; # we only need the first four entries print Dumper \@bytes; my $num = unpack 'N', pack 'C4', @bytes; print sprintf "%08x (%i)", $num, $num;
But if you get a string of four bytes, one of the two pack templates "N" or "V" will help you. See the following:
my $str = "\xDE\xAD\xBE\xEF"; my $num = unpack 'N', $str; print sprintf "%08x (%i)", $num, $num;
But I already told you this and you didn't show any code.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: converting artibrary binary data to numeric values
by markle (Initiate) on Oct 01, 2012 at 21:27 UTC | |
Re^4: converting artibrary binary data to numeric values
by markle (Initiate) on Oct 01, 2012 at 22:08 UTC | |
by Corion (Patriarch) on Oct 02, 2012 at 07:18 UTC | |
by markle (Initiate) on Oct 02, 2012 at 20:31 UTC | |
by afoken (Chancellor) on Oct 02, 2012 at 06:21 UTC |
In Section
Seekers of Perl Wisdom