• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Urgent C++ question

UlricT

Golden Member
I simply cannot figure this out:

I am doing some work on hex values, and I need to output values as sets of 2: 00 FF 03 4D etc...
My problem is that the values with a leading 0 (04 00 0F etc) are coming out only as 4 0 F.

Here is what I am using to output:
cout << hex << (buffer&0xff)<<endl;

any suggestions as to what I can do???
 
Originally posted by: UlricT
I simply cannot figure this out:

I am doing some work on hex values, and I need to output values as sets of 2: 00 FF 03 4D etc...
My problem is that the values with a leading 0 (04 00 0F etc) are coming out only as 4 0 F.

Here is what I am using to output:
cout << hex << (buffer&0xff)<<endl;

any suggestions as to what I can do???

Store it as a string? Sorry, dunno C++, but free bump. 😛
 
got it... used some dumb if statements to get around the problem. Basically converted to a decimal... compared whether < 16, and if so put a "0" at the beginning 😛
 
Originally posted by: UlricT
got it... used some dumb if statements to get around the problem. Basically converted to a decimal... compared whether < 16, and if so put a "0" at the beginning 😛
Another way would be to add 256 to the origbinal number, conber it to hex and stip off the leading character. No if required

 
Back
Top