{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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… Themidtermis NEXT Wednesday ! Beprepared to writecodeon your midterm!
Image of page 1

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

View Full Document Right Arrow Icon
ASCII Question : How do two spies transmit a messageover 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 = .-.. l --- o Agent 7 “Hello 8” Agent 8 8 = ---.. ---.. 8 They can’t send the shapeof an H over the wire, so they send pulses instead.
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 l = 01101100 01101100 01101111 Agent 7 “Hello 8” 8 = 00111000 00111000 Agent 8 H e l l o 8 (Humans arebad at reading these“binary” numbers, so wetend to use decimal numbers instead. But the idea’s thesame.)
Image of page 3

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

View Full Document Right 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 typea character on thekeyboard, it’s converted into a number and stored in thecomputer’s memory! 65 50
Image of page 4
The ASCII Code So if you could createyour own encoding, how would it work? What number would you useto represent A ? How about for little a ? What about for a # sign? Or a & sign? How would you represent thedigits 0 , 1 , 2 9 ?
Image of page 5

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

View Full Document Right Arrow Icon
Characters and ASCII Every symbol on thekeyboard: letter , digit , period , space , etc. is represented by a numeric valuein 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 madeup an encoding: theASCII Code.
Image of page 6
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 morecompletetable:
Image of page 7

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

View Full Document Right Arrow Icon
Characters and ASCII main() { char c; cout << “Enter a char: “; cin >> c; cout << “Your char: “ << c; } When you typein a character like‘A’, thecomputer converts it into a number and stores thenumber 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 .
Image of page 8
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 beused to represent theletter ‘ B ’?
Image of page 9

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

View Full Document Right 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 usesymbolic characters or ASCII (numeric) values. c2 67 C C ‘A’ = 65 ‘B’ = 66 ‘C’ = 67 ... ‘Z’ = 90 When you use cout to print a char variable , cout converts the number back to a symbol for display on thescreen.
Image of page 10
main() { char c1 = ‘!’ ; char c2 = 33 ; cout << c1 << endl; cout << c2 << endl; } Characters and ASCII c1 33 c2 33 ! ! ‘ ’ = 32 ‘!’ = 33 ... ‘/’ = 47 When using char variables in C++, you may usesymbolic characters or ASCII (numeric) values.
Image of page 11

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern