Page 1 of 1

sprintf() and hexadecimal formatting

Posted: Wed Mar 11, 2009 9:18 pm
by Chris Corbyn
I like to think I'm pretty clued up on how to use sprintf()/printf() to generating strings with the correct format, but I wonder of somebody can help me rule-out the possibility of doing this...

Code: Select all

$val = 0xAFED78; //Pure integer value in hex
printf(" ... something to with =%02X ? ... ", $val);
 
/*
=AF=ED=78
*/
I don't think it's possible to do a single call and it requires some pre-processing of $val, but just on the off-chance does anyone know if there's a way?

Re: sprintf() and hexadecimal formatting

Posted: Thu Mar 12, 2009 3:59 am
by Weirdan
You mean your format string is controlled by a malicious person? You're screwed then.