How do I convert int to binary or hex data?
I need convert int, short, int64 to hex data or binary data.
thank.
Printable View
How do I convert int to binary or hex data?
I need convert int, short, int64 to hex data or binary data.
thank.
What do you mean by "Binary/Hex Data?" in windows, all data (Char's, Strings, Integers, etc...) is stored as bytes. The bytes are a sequence of 8-binary bits.
Now, i assume you want to convert an integer to a string that represents the binary/hex data
so 255 will be hex 000000FF and Binary 00000000000000000000000011111111.
How do you do this?
There is 2 magic functions:
1. _itoa - converts an integer to Hex / binary
Use the following code:
int to hex
int integer = 255;
char Hex[9];
_itoa(integer, Hex, 16)
int to Bin
char binary[33];
int integer = 255;
_itoa(integer, binary, 2);
2. _i64toa - same as itoa, but for int64s
---===---
I'm not here for the rates, but rating a post is a good way for me to know how much i helped.
---===---
Daniel