how do I write just one byte in hex?

Nov 6, 2011 at 5:43am
and how do I write 2 bytes in hex as well?
I am wondering if c++ is not the language for me as a lot of these kinds of things come up often.
Nov 6, 2011 at 5:57am
Of course C++ allows you to manipulate hexadecimals. You need to use the 0x prefix when dealing with them so that the compiler knows you want a hexadecimal and not a decimal integer. There is no type set aside for hexadecimals... just use a normal long/long long/short int.

As for manipulating individual byes... the type of an unsigned byte in C++ is unsigned char. The same type (albeit sans the unsigned prefix) is used for handling ASCII characters, but they're still basically 1-byte integers. If, when dealing with input/output, you make sure that it's not handled as an ASCII character, then you should be fine.

-Albatross
Last edited on Nov 6, 2011 at 6:00am
Nov 6, 2011 at 12:20pm
What do you mean by
write just one byte in hex
? Do you mean write 0-9 or A-F? or do you mean just 8bit of a 16bit number?
You can write the number in any numerical system you like and then just display it in another. Say use a binary or decimal numerical system and then represented as hex. Is this satisfactory for you?
Topic archived. No new replies allowed.