1 / 9

Computers and Representations Ascii vs. Binary Files

CS100: Into to Computer Science. Computers and Representations Ascii vs. Binary Files. Core Quantitative Issue Number Representations.

paniz
Download Presentation

Computers and Representations Ascii vs. Binary Files

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS100: Into to Computer Science Computers and RepresentationsAscii vs. Binary Files 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

  2. Overview 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.

  3. The 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.

  4. Example 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. Let’s 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.

  5. An ASCII TABLE

  6. Building An ASCII Table Start with a number N=65 and repeatedly divide it by 2…. For each column we determine whether it is odd or even using MOD()…. 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’) -> 65 CHAR(65) -> ‘A’

  7. Building 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(G1+1) =Concatenate(M2,L2,…) =CODE(F1) =INT(G1/2)

  8. Expanding 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.

  9. Assignment • 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.

More Related