Thread: Ascii to Hex

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    124

    Ascii to Hex

    I have been constructing an assembly program based on accepted single characters integers, and converting them into the numerical Hex value. I was curious how scanf() transforms single characters into their integer equivalent from input. I know you can convert by subtracting base value (ascii Hex value of 0 ). Beside using the multiplication method ( seems too slow), is there any other method to combine the single integers?
    Last edited by Darkinyuasha1; 04-03-2010 at 09:13 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    scanf (and your program, or anything else) receives them as hex values in the first place. When I push 'a' on my keyboard, the keyboard sends 97 to the computer, which is what it gets.

    If you mean how does "487" get turned into the number 487, you can get a little fancy (if ASCII) in that the low three bits of a numeric character are that value, BUT you can't multiply by 10 just by shifting. (You can do some shifts and an add, of course.)

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    124
    so what would be a better method to turn for example "200" in ascii to the numerical value 200?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Darkinyuasha1 View Post
    so what would be a better method to turn for example "200" in ascii to the numerical value 200?
    better than scanf?
    strtol
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ascii to hex and hex to Ascii
    By beon in forum C Programming
    Replies: 1
    Last Post: 12-26-2006, 06:37 AM
  2. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  3. Encrypting text file with ASCII hex
    By supaben34 in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2005, 06:35 PM
  4. Hex to Ascii conversion
    By Ryno in forum C Programming
    Replies: 2
    Last Post: 03-24-2005, 09:16 AM
  5. ASCII v's hex
    By sononix in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2005, 05:18 PM