I have a four-byte string read from a binary file, which is supposed to represent an integer.
How do I dervive the integer?
Example:
my $s = '\xa8e2~';
my $i = stoi($s);
printf "%X", $i; #gives "0x7e3265a8"
The solution in C is simply:
fread(&i,4,1,fp);
$i = unpack("s", $s)may work, but it depends on signed/unsigned and byte ordering so you’ll probably end up here: http://perldoc.perl.org/perlpacktut.html#Integers