ill sprintf() behavior w/ HEX type

From: Date: Thu, 21 Nov 2002 07:51:26 +0000
Subject: ill sprintf() behavior w/ HEX type
Groups: php.general 
Request: Send a blank email to php-general+get-125383@lists.php.net to get a copy of this message
Using PHP/4.2.2 & Apache/1.3.26 on Linux 2.4.17 I'm trying to format a HEX value into an 8-byte string, that is zero-padded to the left, using sprintf(). Simple enough. $sprintf( "%08x", "fa23d" ); This should return "000fa23d". But it returns "00000000". Since that doesn't work, I'm using this: $sprintf( "%08s", "fa23d" ); Which returns the value I expected from the earlier case. But I'd rather the earlier case work the way it's supposed to. Has anyone else seen this behavior from sprintf() w/ hex types, or can ya point out something errant in my usage? If not ... it's going into the bug system. I haven't seen anything open in there about this oddity. There's some test code below the .sig if anyone wants to try it out. THX, ~Chris <?php $myDec = 1024573; $myHex = dechex( $myDec ); // "fa23d" $myFormattedHex1 = sprintf( "%08x", $myHex ); // should be "000fa23d" $myFormattedHex2 = sprintf( "%08s", $myHex ); header( "Content-type: text/plain" ); print <<<TXT1 Decimal: ${myDec} Hex: ${myHex} Formatted Hex (%08x): ${myFormattedHex1} Formatted Hex (%08s): ${myFormattedHex2} TXT1; ?>

« previous php.general (#125383) next »