Title: Computers and Representations Ascii vs. Binary Files
1Computers and RepresentationsAscii vs. Binary
Files
CS100 Into to Computer Science
Core Quantitative Issue Number Representations
Over the last few million years, Earth has
experienced numerous ice ages when vast regions
of the continents were glaciated and sea level
was lower as a result.. How much did sea level
drop during these glaciations?
Supporting Issues Number sense Numerical
Computations Algorithms
Prepared by Fred Annexstein University of
Cincinnati Some Rights Reserved
2Overview
Most people classify files in two categories
binary files and ASCII (text) files. You've
actually worked with both. Most programs you work
(Excel and Powerpoint) store representations in
binary format. On other hand, Web pages, XML
files, and computer programs are stored as ASCII
files. An ASCII file is defined as a file that
consists of ASCII characters. It's usually
created by using a text editor like emacs, pico,
vi, Notepad, etc. There are fancier editors out
there for writing code, but they may not always
save it as ASCII. As an aside, ASCII text files
seem very "American-centric". After all, the 'A'
in ASCII stands for American. However, the US
does seem to dominate the software market, and so
effectively, it's an international
standard. Computer science is all about creating
good abstractions. Sometimes it succeeds and
sometimes it doesn't. Good abstractions are all
about presenting a view of the world that the
user can use. One of the most successful
abstractions is the text editor. Another
successful abstractions is the spreadsheet.
3The Difference between ASCII and Binary Files
An ASCII file is confusingly a binary file that
stores ASCII codes. ASCII code is a 7-bit code
stored in a one byte. To be more specific, there
are 128 different ASCII codes, which means that
only 7 bits are needed to represent an ASCII
character.
- The minimum workable size in computers is 1 byte,
and those 7 bits are the low 7 bits of an 8-bit
byte. The most significant bit is set to 0. That
means, in any ASCII file, you're wasting 1/8 of
the bits. In particular, the most significant bit
of each byte is not being used. - Hence an ASCII file is a special kinds of binary
files where each byte is written in ASCII code.
General binary file has no such restrictions. - What makes a file a binary file is the fact that
each byte of a binary file can be one of 256 bit
patterns. They're not restricted to the ASCII
codes.
4Example of ASCII files
Suppose you're editing a text file with a text
editor like Notepad. Because you're using a text
editor, you're pretty much editing an ASCII file.
In this brand new file, you type in "cat". That
is, the letters 'c', then 'a', then 't'. Then,
you save the file and quit. In Excel you are
editing a binary file rather than ASCII.
- Lets look at the issue of ASCII encoding. If you
look up an ASCII table on the web, you will
discover the ASCII codes are written in different
formats, including decimal (base 10), Hexadecimal
(base 16), and binary (base 2) - Here's how it may look
- Text 'c' 'a' 't'
- Decimal 99 97 116
- Hex 0x63 0x61 0x74
- Binary 0110 0011 0110 0001 0111 1000
- Each time you type in an ASCII character and save
it, an entire byte is written which corresponds
to that character. This includes punctuations,
spaces, and so forth. Thus, when you type a 'c',
it's being saved as 0110 0011 to a file. - Next we look at a table and build such in Excel
spreadsheet.
5An ASCII TABLE
6Building An ASCII Table
Start with a number N65 and repeatedly divide it
by 2.
65 32 16 8 4 2 1
For each column we determine whether it is odd or
even using MOD().
1 0 0 0 0 0 1
We can switch between numbers and characters
using two special functions CODE() and
CHAR(). Using CONCATENATE() you can put together
the string of odd/even values as the binary
representation of N CODE(A) -gt 65 CHAR(65) -gt
A
7Building Table
The only input value is F2 A -- all other
cells are functions!
Recreate the spreadsheet below to calculate the
drop in sea level if the ice volume at the last
glacial maximum was 70 million km3, in contrast
to the current volume of 25 million km3.
CHAR(G11)
Concatenate(M2,L2,)
CODE(F1)
INT(G1/2)
8Expanding your Table and Translation
Expanding Now Replace the A in the first row
with a space character to obtain a full ASCII
table for the usual text characters.
Translation You can use function VLOOKUP() to
translate an ASCII-BINARY encoded message into
text string and visa versa. Type in sentence The
fat cat. with one character per cell. Underneath
produce the ASCII equivalent representation in
binary, as follows.
T h e f a t c a t .
1010100 1001000 1100101 1100110 1100001 1110100 1100011 1100001 1110100 101110
9Assignment
- Find a small poem or quotation. Translate each
character into ASCII automatically in your
worksheet. - In the Communication tools post it to web as
comma separated values. - Import one such quote from another student and
translate it using VLOOKUP() function. - Turn in your spreadsheet to Bb.