ASCII and Different Bases

This is a discussion on ASCII and Different Bases within the C++ Programming forums, part of the General Programming Boards category; Hey, Someone said in another message that a text file is a string of 3 digit numbers representing the letters ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    27

    ASCII and Different Bases

    Hey,
    Someone said in another message that a text file is a string of 3 digit numbers representing the letters and symbols (I know when it gets to the hard drive though it's binary). If you converted ASCII’s three digit numbers to hexadecimal, for example, then wrote the hex directly into a binary file would that mean the file is smaller than the original ASCII? If "m" in ASCII is equal to 109, then in hex it would equal 6D. Wouldn’t this use one letter space less of memory?

    Gr3g
    Chance favors the prepared mind.

    Vis. C++ 6.0

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    If you write text to a file in binary mode, the size of the file would stay the same (each character takes up one byte).

    If you write numbers to a file in binary mode (for example, int, float, double), then the size of the file would almost always become smaller, because an int, float, or double, or other number in memory is always a fixed size. For example, typical sizes for numbers:

    int - 4 bytes
    float - 4 bytes
    double - 8 bytes

    for C++ streams, to write files in binary, open the file in binary mode, then use write() and read() to write or read in binary.

    ofstream out("binary.dat",ios::binary);
    out.write(...)
    Last edited by swoopy; 04-05-2002 at 05:46 PM.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    38
    Yeah...To be stored in a hard drive, every number base must be converted into binary. Even if 109 is more decimal digits than 6D is, it is still converted into the binary form, which ends up being the same value.
    Show me a man who cannot bother to do little things, and I'll show you a man who cannot be trusted to do big things.

    -Bill Cosby

  4. #4
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    remember: the highest ascii character is 255 which is equal to 0xFF which is equal to 1111 1111.

  5. #5
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Now isn't it time for someone to bring up those oh so annoying BCDs?

Popular pages Recent additions subscribe to a feed

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