Possible bug: Using "h" and "H" with unpack()

From: Date: Thu, 10 Jan 2002 17:53:07 +0000
Subject: Possible bug: Using "h" and "H" with unpack()
Groups: php.general 
Request: Send a blank email to php-general+get-80054@lists.php.net to get a copy of this message
Good day, I can not seem to get the "h" or "H" options to work at all with unpack(). I'm pretty sure that I have this right, although the documentation for this function is bit sparse. The code: print "The data has been encoded (".strlen($varbind)." bytes in size)."; print "Hex: <PRE> "; $hex_unpacked = unpack( "H*" , $varbind ); for ( $i=1 ; $i <= sizeof($hex_unpacked) ; $i++) { print $hex_unpacked[$i] . "|"; } print "\n". sizeof($hex_unpacked) . " elements unpacked.\n"; print "</PRE>\n"; prints out: The data has been encoded (20 bytes in size).Hex: | 1 elements unpacked. .. for the sample binary string. If I use "C*" instead of "H*" (to print out characters instead of hex strings) then I get the expected result: The data has been encoded (20 bytes in size).Hex: 6|49|0|2|52|0|0|0|0|48|57|6|49|0|2|52|0|0|0|0| 20 elements unpacked. Now, I can work around this problem by combining sprintf with the "C*" format to format the characters into hex strings. But, if this is a bug then it should be addressed. Alternatively, if unpack() isn't supposed to support all of the options of pack() (such as "H" and "h") then the documentation should state which options it can support. Is this a bug, or have I just missed something? ============================ Darren Gamble Planner, Regional Services Shaw Cablesystems GP 630 - 3rd Avenue SW Calgary, Alberta, Canada T2P 4L4 (403) 781-4948

« previous php.general (#80054) next »