Thread: ASCII v's hex

  1. #1
    Registered User
    Join Date
    Aug 2004

    ASCII v's hex

    I'm trying to access a binary file that i have created very simple and straight forward
    fwrite( GlobalImageBuffer, 1, 200, fp);
    Now when i try and view it in a hex editor i cant view all the characters correctly, It seems that some of the ascii codes share hex codes
    ie hex 41 could be the number "65" or the letter "A", could some one explain why i can't view the binary file correctly, what correct tools do i need currently using 010 editor


  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    There is no difference between "ascii" and "hex". It's simply a matter of you displaying it how you want to. All ascii characters have a decimal value. Oddly enough, decimal can be converted (read: displayed in) to hex. It's up to you do pick what way you want to display whatever it is you're displaying.

    Hope is the first step on the road to disappointment.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    1,398 hex 41 could be the number "65" or the letter "A"...

    To expand a bit on what quzah said...

    As you know, your computer's RAM stores everything as binary numbers. That number might just be a number (integer) or, it might represent an ASCII character, it might be a CPU machine language instruction, it might represent the color of a pixel, it might be an unused memory location with "garbage" in it. There is nothing about the number itself to indicate what it's for!

    So, your program, or the operating system, or the BIOS... something... has to keep track of the meaning and purpose of the data at each memory address.

    The same is true for you hard disk, every file is just a sequence of numbers.

    ...could some one explain why i can't view the binary file correctly...
    What do you mean by "correctly"?

    The hex editor doesn't know what the "numbers" represent either. Whenever the hex editor sees any number between 32 and 127 (decimal), it displays the associated character.

    If you've written character-A to a file, your hex editor should display 41 in the hex-field, and 'A' in the ASCII-field. (Every hex editor I've seen displays ASCII values to the right of the hex values.) If you've saved the number-65 (decimal) to a file, the hex editor should again display 41 in the hex-field, and 'A' in the ASCII-field.

    I think the hex editor should keep everything straight, but things can get screwy due to byte-order. You are probably working on a 32 bit machine, with a 16 bit ATA/IDE drive connector, and your hex editor is converting bytes (8-bits) to ASCII.

    BTW - The only reason hex is used is because binary numbers are difficult (for humans) to read, and write (or speak). And, it's easier to convert between binary and hex, than binary and decimal. You can easily learn to do hex-binary conversions in your head.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Char to ASCII Hex Value Troubles
    By MattMik in forum C++ Programming
    Replies: 6
    Last Post: 03-25-2008, 02:17 PM
  2. Ascii to hex and hex to Ascii
    By beon in forum C Programming
    Replies: 1
    Last Post: 12-26-2006, 06:37 AM
  3. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. Encrypting text file with ASCII hex
    By supaben34 in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2005, 06:35 PM
  5. Hex to Ascii conversion
    By Ryno in forum C Programming
    Replies: 2
    Last Post: 03-24-2005, 09:16 AM