lecture8

lecture8 - Monday, Nove be 1 mr C ode TheAS I I C Arrays,...

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

View Full Document Right Arrow Icon
Monday, November 1 st The ASCII Code Arrays, arrays, arrays… The midterm is NEXT Wednesday ! Be prepared to write code on your midterm!
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 = --- .... . He . 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.
Background image of page 2
ASCII Instead of using dots and dashes, modern computers send and store messages by encoding them into series of 1 s and 0 s. H = 01001000 e = 01100101 l = 01101100 o = 01101111 0100 1000 0110 0101 01101100 01101111 Agent 7 “Hello 8” 8 = 00111000 00111000 Agent 8 H e 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.)
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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 0 , 1 2 9 ?
Background image of page 5

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

View Full DocumentRight Arrow Icon
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.
Background image of page 6
The ASCII Chart: 48-63 65 97 Here’s a more complete table:
Background image of page 7

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

View Full DocumentRight Arrow Icon
Characters and ASCII main() { char c; cin >> 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 .
Background image of page 8
Characters and ASCII main() { char c; cin >> c; } Enter a char: B Your char: B c 66 Can you guess what number will be used to represent the letter ‘ B ’?
Background image of page 9

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

View Full DocumentRight Arrow Icon
main() { char c1 = ‘C’ ; char c2 = 67 ; cout << c1 << endl; cout << c2 << endl; } Characters and ASCII c1 67 When using char variables in C++, you may use symbolic characters or ASCII (numeric) values. c2 C C ‘A’ = 65 ‘B’ = 66 ‘C’ = 67 ... ‘Z’ = 90 When you use cout to print a char variable , converts the number back to a symbol for display on the screen.
Background image of page 10
main() { char c1 = ‘!’ ; char c2 = 33 ; cout << c1 << endl; cout << c2 << endl; } Characters and ASCII c1 33 c2 ! ! ‘ ’ = 32 ‘!’ = 33 ... ‘/’ = 47 When using char variables in C++, you may use symbolic characters or ASCII (numeric) values.
Background image of page 11

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

View Full DocumentRight Arrow Icon
Characters and ASCII void main(void) { char ch; cin >> ch; cout << ch << endl; cout<< static_cast<int>( ch ) ++ch; // treat it just like a number!
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/07/2009 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

Page1 / 48

lecture8 - Monday, Nove be 1 mr C ode TheAS I I C Arrays,...

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

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