in reply to Convert binary file to ascii
... @samples = split(//,$_); while (@samples) { print OUTFILE sprintf("0x%02x%02x",map{ord}reverse splice @sam +ples,0,2 ).", ";
ord returns the ordinal number (ASCII value) of a char in decimal, i.e. a number between 0..255. If there's a 'f' in that stream, that will be converted into 102. sprintf("0x%02x",ord "f") gives 0x66.
But there are more elegant ways to do this. See pack and unpack.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|