Thread: ASCII or DEC? (pgm format)

  1. #1
    Registered User
    Join Date
    Nov 2018
    Posts
    1

    ASCII or DEC? (pgm format)

    Hi,

    I'm afraid this is a stupid question...

    when I search for the pgm format and how it works on Wikipedia for exemple, I learn that there are an ASCII and a binary version. Each time a number is written in DEC, it reads that they are in ASCII...?
    Do we say ASCII when talking about decimal numbers?

    Thank you

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    Computers store numbers internally in binary for efficiency reasons. When it displays a number to you it converts it to a string of (possibly ASCII) character values that are sent to the console where they are interpreted as character codes. When you enter a number you are just entering decimal characters which need to be translated into the actual internal numeric value, something like this:
    Code:
    int read_int() {
        int c;
        while (isspace(c = getchar()) ;
        int n = 0;
        while (isdigit(c = getchar())
            n = n * 10 + (c - '0');   // subtract ascii code for character '0' to get value of digits from '0' to '9'
        return n;
    }
    So the "ascii" form is characters that represent numbers whereas the binary form is the actual bit patterns of the internal number format stored in the file.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    ASCII is just how we encode characters -- when you press the button that says "4" on your keyboard, ASCII determines the code that is stored for that.

    Decimal is just how you are writing the number in characters -- the value that is 100 in decimal is 144 in octal and 64 in hex and so on; that base determines what characters are used, but doesn't have anything to do with ASCII coding as such.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing Integer Value to LCD in ASCII Format
    By JTerry in forum C Programming
    Replies: 5
    Last Post: 01-04-2011, 10:31 AM
  2. ASCII character with ASCII value 0 and 32
    By hitesh_best in forum C Programming
    Replies: 4
    Last Post: 07-24-2007, 09:45 AM
  3. ascii rpg help
    By aaron11193 in forum C Programming
    Replies: 18
    Last Post: 10-29-2006, 01:45 AM
  4. Ascii
    By Ideswa in forum C++ Programming
    Replies: 2
    Last Post: 03-26-2006, 08:57 AM
  5. Switch from .ms3d to the ASCII format?
    By Shamino in forum Game Programming
    Replies: 18
    Last Post: 01-23-2006, 09:28 PM

Tags for this Thread