How do I convert int to binary or hex data?
 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: How do I convert int to binary or hex data?

#### Hybrid View

1. Junior Member
Join Date
Apr 2000
Posts
3

## How do I convert int to binary or hex data?

How do I convert int to binary or hex data?

I need convert int, short, int64 to hex data or binary data.

thank.

2. Elite Member
Join Date
Dec 1999
Location
Israel
Posts
2,851

## Re: How do I convert int to binary or hex data?

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

3. Junior Member
Join Date
Aug 2013
Posts
1

## Re: How do I convert int to binary or hex data?

Originally Posted by DanielK
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
thank you Daniel and i agree with you. you solution solved my problem. thanks again.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•