Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Computers and Representations Ascii vs. Binary Files Over the last few million years, Earth has experienced numerous ice ages when vast regions of the.

Similar presentations


Presentation on theme: "1 Computers and Representations Ascii vs. Binary Files Over the last few million years, Earth has experienced numerous ice ages when vast regions of the."— Presentation transcript:

1 1 Computers and Representations Ascii vs. Binary Files 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? Prepared for SSAC by Paul Butler – The Evergreen State College, Olympia, WA 98505 © The Washington Center for Improving the Quality of Undergraduate Education. All rights reserved. 2006 Supporting Quantitative Issues Number sense: Significant figures Algebra: Manipulating of equations Geometry: circle: area Geometry: sphere: surface area SSAC2006.QE697.PB1.2 Core Quantitative Issue Estimation

2 2 Overview Most people classify files in two categories: binary files and ASCII (text) files. You've actually worked with both. Any program you write (C/C++/Perl/HTML) is almost surely an ASCII file. 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. Slide 3 states the problem and discusses assumptions, estimation and significant figures. Slide 4 shows how to estimate the surface area of world oceans. Slide 5 shows how to estimate sea-level drop during glacial maxima. Slides 6 - 8 evaluate the effect of one of the underlying assumptions. Slides 9 and 10 give the assignment to submit to your instructor.

3 3 The Difference between ASCII and Binary Files? An ASCII file is a binary file that stores ASCII codes. Recall that an ASCII code is a 7-bit code stored in a byte. To be more specific, there are 128 different ASCII codes, which means that only 7 bits are needed to represent an ASCII character. However, since the minimum workable size is 1 byte, those 7 bits are the low 7 bits of any byte. The most significant bit is 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. Although ASCII files are binary files, some people treat them as different kinds of files. I like to think of ASCII files as special kinds of binary files. They're binary files where each byte is written in ASCII code. A full, general binary file has no such restrictions. Any of the 256 bit patterns can be used in any byte of a binary file. We work with binary files all the time. Executables, object files, image files, sound files, and many file formats are binary files. What makes them binary is merely the fact that each byte of a binary file can be one of 256 bit patterns. They're not restricted to the ASCII codes.

4 4 Suppose you're editing a text file with a text editor. 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. What happens? For the time being, we won't worry about the mechanism of what it means to open a file, modify it, and close it. Instead, we're concerned with the ASCII encoding. If you look up an ASCII table, you will discover the ASCII code for 0x63, 0x61, 0x74 (the 0x merely indicates the values are in hexadecimal, instead of decimal/base 10). Here's how it looks: ASCII 'c' 'a' 't' Hex 63 61 74 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. I recall one time a student has used 100 asterisks in his comments, and these asterisks appeared everywhere. Each asterisk used up one byte on the file. We saved thousands of bytes from his files by removing comments, mostly the asterisks, which made the file look nice, but didn't add to the clarity. Thus, when you type a 'c', it's being saved as 0110 0011 to a file. Example of ASCII files

5 5 We can switch between numbers and Characters using CODE() and CHAR(). Using CONCATENATE() you can put together the string of odd/even values as the binary representation of N CODE(‘A’) -> 65 CHAR(65) -> ‘A’ Building An ASCII Table Start with a number N and repeatedly divide it by 2…. 6532168421 For each column we determine wheter it is odd or even using MOD()…. 1000001

6 6 Recreate the spreadsheet below to calculate the drop in sea level if the ice volume at the last glacial maximum was 70 million km 3, in contrast to the current volume of 25 million km 3. Building Table The only input value is F2 = ‘A’ -- all other cells are functions! =Concatenate(M2,L2,…) =CHAR(G1+1)=CODE(F1) =INT(G1/2)

7 7 Use function VLOOKUP() to translate an ASCII-BINARY encoded message into text string.

8 8 1.Find a small poem or quotation. Translate each character into ASCII automatically in your worksheet. 2.In the Communication tools Post it to web as comma separated values. 3. Import one such quote from another student and translate it using VLOOKUP() function. Assignment


Download ppt "1 Computers and Representations Ascii vs. Binary Files Over the last few million years, Earth has experienced numerous ice ages when vast regions of the."

Similar presentations


Ads by Google