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;
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php