You will want to look at the pack and unpack functions if you are routinely converting between numbers and their binary representation as characters.
Usually, Perl does the Right Thing, but if you want to be safe from Unicode encodings, use the binmode() call after opening your file, so you get full control over what Perl writes to the file:
open my $fh, "<", $fname or die "Couldn't open $fname: $!"; binmode $fh; seek $fh, 258, 0; read $fh, (my $buf), 1; $buf = unpack "c", $buf; ...
Why do you want to convert the stuff from the character to the integer at all? If there are no calculations to be made, you will likely be faster by not converting at all. But still, the IO overhead of reading the file will likely dwarf any optimizations you might make in your code ...
Update: PodMaster pointed me to Pack/Unpack Tutorial (aka How the System Stores Data) by pfaut - you should read that tutorial.
Update 2: frodo72 pointed out a typo in binmmode - thanks frodo72!
In reply to Re: Binary Reading Questions
by Corion
in thread Binary Reading Questions
by Eyeth
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |