LECTURE8

LECTURE8 - Monday, November 1 st • The ASCII Code •...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Monday, November 1 st • The ASCII Code • Arrays, arrays, arrays… The midterm is NEXT Wednesday ! Be prepared to write code on your midterm! ASCII Question : How do two spies transmit a message over a telegraph? Answer : They have to encode the message as a series of short and long pulses which can travel over the wire. H = .... e = . l = .-.. o = --- .... . H e .-.. l l = .-.. .-.. l--- o Agent 7 “Hello 8” Agent 8 8 = ---..---.. 8 They can’t send the shape of an H over the wire, so they send pulses instead. ASCII Instead of using dots and dashes, modern computers send and store messages by encoding them into series of 1 s and s. H = 01001000 e = 01100101 l = 01101100 o = 01101111 0100 1000 0110 0101 01101100 l = 01101100 01101100 01101111 Agent 7 “Hello 8” 8 = 00111000 00111000 Agent 8 H e l l o 8 (Humans are bad at reading these “binary” numbers, so we tend to use decimal numbers instead. But the idea’s the same.) ASCII This encoding is called the “ASCII” code. Computers represent letters, punctuation and digit symbols using this code, basically storing each character as a number . When you type a character on the keyboard, it’s converted into a number and stored in the computer’s memory! 65 50 The ASCII Code So if you could create your own encoding, how would it work? What number would you use to represent A ? How about for little a ? What about for a # sign? Or a & sign? How would you represent the digits , 1 , 2 … 9 ? Characters and ASCII Every symbol on the keyboard: letter , digit , period , space , etc. is represented by a numeric value in memory ! ‘A’ = 65, ‘B’ = 66, ..., ‘Z’ = 90 ‘a’ = 97, ‘b’ = 98, ..., ‘z’ = 122 ‘ ‘ = 32 (space), ‘!’ = 33, ‘,’ = 44, etc... ‘0’ = 48, ‘1’ = 49, ‘2’ = 50,... ‘9’ = 57 Well, a long time ago a bunch of computer geeks got together and made up an encoding: the ASCII Code. The ASCII Chart: 0-15 16-31 32-47 48-63 64-79 80-95 96-111 112-127 65 97 48 Here’s a more complete table: Characters and ASCII main() { char c; cout << “Enter a char: “; cin >> c; cout << “Your char: “ << c; } When you type in a character like ‘A’, the computer converts it into a number and stores the number in memory. Enter a char: A Your char: A c 65 When you print a char variable out, the computer converts it back to a symbol . Characters and ASCII main() { char c; cout << “Enter a char: “; cin >> c; cout << “Your char: “ << c; } Enter a char: B Your char: B c 66 Can you guess what number will be used to represent the letter ‘ B ’? main() { char c1 = ‘C’ ; char c2 =...
View Full Document

This note was uploaded on 04/10/2012 for the course CS 31 taught by Professor Melkanoff during the Winter '00 term at UCLA.

Page1 / 48

LECTURE8 - Monday, November 1 st • The ASCII Code •...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online