hexadecimal char to int.

This is a discussion on hexadecimal char to int. within the C++ Programming forums, part of the General Programming Boards category; how can I transfer a char[] holding an hex value (something like : "FFFAFF88" ) into a simple int? I ...

  1. #1
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117

    hexadecimal char to int.

    how can I transfer a char[] holding an hex value (something like : "FFFAFF88" ) into a simple int?

    I already made one to transfer decimal char into int but hex im kinda clueless..

    Dont tell me to use another function held in some library I wanna make my own using only <iostream> if possible.

    thx
    Luigi

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,607
    Well, if you have already done a decimal version, then you're halfway there. Hex numbers are base 16. So if you have a number like "FF", the one's place contains 15, and the sixteen's place contains 15...so 16*15 + 1*15 = 255, or 0xFF.

    0xA3F = (16*16)*10 + 16*3 + 1*15 = 2623

    gg

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You can modify the FAQ example to do the work for you, if you want.

    Or, if you don't want stringstreams, try strtol() as per this FAQ example

    But which every way you choose, FFFAFF88 might not fit into a simple int due to size limitations.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    I wrote a function a while back that converts between bases 2-36.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Whoops! Forgot to attach it.
    Attached Files Attached Files
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  2. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  3. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  4. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 03:24 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21