Coding & Computation or What s all this about 1s and 0s? File: coding-computation-slides.tex. 1
File: coding-computation-slides.tex. Created: January 28, 2001, sok. 1-1
Topics Aim: Communicate certain fundamental concepts about computers and computing. Relax. Digital encoding (Digital) computation Fundamental programming Applied programming 2
Digital encoding Digital discrete (Analog continuous) Encode = to put into or represent with a code Code a system of symbols... used for communication (Morse code, braille, one if by land,... ), for instructing computers (machine code), &c. Code are discrete: elements are in or out. Period. 3
Digital encoding: Examples of codes Written words: Bob, Carol, Ted, Alice Words stand for things, events, relations, etc. sentences, etc. Make up Letters of the alphabet What an idea! With a few letters, all the words; with a few thousand words, an infinite number of sentences. 4
Digital encoding: Examples of codes Morse code: Dots: Dashes: A J S B K T C L U D M V E N W F O X G P Y H Q Z I R (There s more for other symbols, e.g. Ä is ) 5
Digital encoding: Comments on Morse code How many elementary / primitive symbols? Answer: 2. Why? How many symbols do we need to cover the letters of the 26 letters of the alphabet? Answer: 2 1 + 2 2 +... + 2 n until > 26, i.e., n = 4. Note: Why not just 2 5? Why do the different letters have the symbol patterns they have? 6
Digital encoding: Examples of codes Braille: array of 3 2 = 6 dots, raised or not. Character codes in computing 1. ASCII (American Standard Code for Information Interchange) Standard in computing. See the IDT book. 2. EBCDIC: IBM mainframes 3. Unicode: For all the world. 7
ASCII Binary code: 1s and 0s. 7 or 8 bits (= binary digits) P is decimal 80 = 8 10 1 + 0 10 0 or in binary = 0 2 7 + 1 2 6 + 0 2 5 + 1 2 4 + 0 2 3 + 0 2 2 + 0 2 1 + 0 2 0 or 01010000 in 8-bit binary. 01010000 in 7-bit binary, with parity even. 11010000 in 7-bit binary, with parity odd. 8
Number coding systems Decimal (10-based) has 10 symbols possible per slot : 0, 1, 2,..., 9 Binary (2-based) has 2 symbols possible per slot : 0 and 1 Octal (8-based) has 8 symbols: 0, 1, 2, 3, 4, 5, 6, 7, and 8 Hexidecimal (16-based) has 16 symbols: 0, 1,..., 9, A, B, C, D, E, and F Number coding can be in any base: 2, 3,..., n. Why base 2 for computers? Why base 8, base 16? 9
Digital encoding. We encode from a list of atomic symbols (e.g., the alphabet) and compose more complex things by combining these symbols (e.g., words are composed of letters of the alphabet, sentences are composed of words). At the most abstract, general level, we can use numbers to be our atomic symbols (numerals, actually). So, e.g., P = 80 decimal = 01010000 binary in ASCII. Let dash ( ) = 0, dot ( ) = 1. Then in Morse code, P = 1001 binary 10
Digital encoding: Comments Conventionality (arbitrariness) Why not P = 1010111? etc. Generality Can one type of encoding encode everything that another type of encoding can encode? Does it matter whether we do decimal or binary? Why? (Prove it!) Wait: 01010000 is a (binary) number, yet it s an encoding of P. Which is it? How can you tell? Why isn t it ÄH in Morse code? Or a sound or a picture or a movie? 11
Digital computation... or a program instruction? Roughly, a computation is a manipulation and/or recognition of a digital encoding A computer is a machine that does computations, that manipulates, recognizes, and acts on digital encodings Our computers work on binary (1s and 0s) encodings. Why? 12
Digital computation Is that all? Can t some computers do more than others? Yes, that s possible. Size, speed, of course. Actually, just a few instructions are sufficient to compute all possible manipulations on binary digital encodings, and these are in turn fully general. An amazing fact. 13
Digital computation So, all real computers are fundamentally equivalent, just some are bigger and faster than others. What about interacting with the world? I/O as we say. Same thing, just hooked to I/O devices. Clarification: manipulations aren t just arithmetic; they re anything (on binary encodings). 14
Fundamental programming Computers run by executing program instructions, one after another. The program instructions instruct the computer to manipulate, recognize, and act upon digital (binary) encodings. How are program instructions represented to the computer? As binary encodings. What about the data used by the program? Same thing. How does it know? Basic cycle: (1) fetch the next instruction (from memory into the CPU), (2) execute the instruction, (3) figure out where the next instruction is and go to (1). 15
Applied programming Don t like them 1s and 0s (machine language) So, higher-level languages: metaphor Compiler: takes your higher-level jottings and translates them into machine language, so your program can be executed. Note: machine language programs are specific to the machine type you are running: Intel X, Intel Y, Macintosh, Sun, Alpha, IBM, etc. 16
Applied programming Interpreter: Accepts a compact semi-compiled (byte-code) version of your jottings and executes it by translating it on the fly to machine code and sending it off for execution. Visual Basic, Excel. Possibility: Interpreters for each type of mahcine (hardware), but all can then execute the same byte-code. Write once, run everywhere. Think of the Internet. And: Java. 17
Applied programming: On the Internet, etc. Where does/can code execute? On your PC (your client, whether Wintel, Mac, Linux, Unix,... ): Your browser (Internet Explorer, Netscape, Hot Metal,... ) On your PC: Spreadsheet programs, word processing programs,... 18
Where does code execute? (con t.) On the server: The Web server program that responds to requests from your browser and serves up files to you. On the server: Business programs that run in response to your inputs from your browser: shopping carts, billing, etc. (Think of buying something on the Web, or participating in an auction.) On the server: Business programs that create HTML pages and send them to you on the fly. PHP, ASP, JSP. 19
Where does code execute? (con t.) On your PC, via your browser: JavaScript, VBScript for graphics and animation (but primitively) On your PC, via your browser: ActiveX (Microsoft) and Java applets Downloaded in real time from the server! Why? Pluses? Minuses? Worries? 20
/* $Header: /home/sok/cvsrepos/misidtbook/coding-computation-slides.t