Ascii to Hex

This is a discussion on Ascii to Hex within the C Programming forums, part of the General Programming Boards category; I have been constructing an assembly program based on accepted single characters integers, and converting them into the numerical Hex ...

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

    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,185
    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
    121
    so what would be a better method to turn for example "200" in ascii to the numerical value 200?

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 05:37 AM
  2. Replies: 11
    Last Post: 03-24-2006, 10:26 AM
  3. Encrypting text file with ASCII hex
    By supaben34 in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2005, 05:35 PM
  4. Hex to Ascii conversion
    By Ryno in forum C Programming
    Replies: 2
    Last Post: 03-24-2005, 08:16 AM
  5. ASCII v's hex
    By sononix in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2005, 04:18 PM

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