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

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

Hybrid View

  1. #1
    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. #2
    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. #3
    Join Date
    Aug 2013
    Posts
    1

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

    Quote Originally Posted by DanielK View Post
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center