> > > > $hex = 0xff; > > $bin = unpack("B32", pack("N", hex $hex)); > > The above assumes big-endian byteorder. For little-endian use > "V" instead > of "N". Or just use "L" when the file has the same byteorder as the > machine you are running this script on. > > Btw, the hex() above is probably wrong. hex() converts a string into a > numeric value by intepreting it as hexadecimal. Essentially, you do it > twice resulting in:
woops, you are correct. the 'hex $hex' assumes it is passed as a string. other than that it works as expected on both my Win2k (intel, little endian) and Solaris (sparc, big endian). The bin result is returned in big endian on both machines, so one would have to be cognizant that the result is not returned in the native format for little endian machines. And yes it depends on how the file is formatted. so we can make some adjustments: -- $hex = '0xff'; #passed as a string $bin = unpack("B32", pack("N", hex $hex)); print $bin; --- $hex = 0xff; $bin = unpack("B32", pack("N", $hex)); #passed as a hex number print $bin; ---- # print in correct order for little endian machines $hex = '0xff'; $bin = unpack("B32", pack("L", hex $hex)); print $bin; ----- Thanks Tassilo ! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]