Hi all,
I'm trying to output the hex value of 255 to a read only dialog box in MFC. pdu[x]=255
sprintf(temp_buffer,"%02x ",pdu[x]);
output+=temp_buffer;
Instead of getting ff, I'm getting ffffffff. Any ideas? Thanks
Shav
Hi all,
I'm trying to output the hex value of 255 to a read only dialog box in MFC. pdu[x]=255
sprintf(temp_buffer,"%02x ",pdu[x]);
output+=temp_buffer;
Instead of getting ff, I'm getting ffffffff. Any ideas? Thanks
Shav
I might be way off here, but the hex value of the base-10 number 255 is 0xFF. It appears that you are passing the decimal number 255 to the dialog box. I might be reading this wrong though.
Yeah, I'm reading in an integer from an edit box. Is there any way to display the number as FF
> Instead of getting ff, I'm getting ffffffff. Any ideas? Thanks
pdu[x] is signed, so it gets sign-extended all the way up to however many bits are in an integer.
Making your pdu unsigned would do it, as would something like a cast, say
sprintf( temp_buffer, "%02x ", (unsigned char)pdu[x] );
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Brilliant, works a treat!