1 / 35

ECE 160 – Comp Programming I Data Structures with C

ECE 160 – Comp Programming I Data Structures with C. Prof. P. H. Viall Office: Research 217 Tel: 999-8240 Web: http://www.ece.umassd.edu/faculty/pviall/ece160/ece160.htm Book: C for Engineers and Scientists: An Introduction to Programming with ANSI C

Download Presentation

ECE 160 – Comp Programming I Data Structures with C

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. ECE 160 – Comp Programming I Data Structures with C Prof. P. H. Viall Office: Research 217 Tel: 999-8240 Web: http://www.ece.umassd.edu/faculty/pviall/ece160/ece160.htm Book: C for Engineers and Scientists: An Introduction to Programming with ANSI C Gary J. Bronson (Editor=Mixer) West Publishing

  2. Tentative Grading • Exams (57%) Best 3 of 4 exams (no makeups) Exams are 1 hour in class exams Exams MAY be open book/note • Homework/Programs (13%) • Final Exam (30%)Note – scheme is tentative – grading may be adjusted ±5%

  3. Working Together • Homework (including programs) – is OK; please indicate who you worked with. Note that working together means just that; not one person working, and one copying. • Exams are definitely an individual endeavor. You may not work together during exams. You may not share any materials during an exam. In general the penalty for cheating on an exam or otherwise covertly attempting to raise your grade on an exam shall be an ‘F’ for the course.

  4. Canceled Classes and Tests • If class is cancelled the day an exam is scheduled, we will have the exam the next time the class meets • If class is cancelled the session prior to the exam (the day you have to ask questions), then the next class meeting will be the “question time”, and the class meeting after that will be the exam

  5. Course Objectives • To learn how a computer stores data, and conversion between various number bases • To learn the fundamentals of using the Unix operating system, including X windows, the c compiler and c preprocessor • To learn the syntax of the c language, including arrays, structures, dynamic allocation, and file access • To learn To learn how to program, and how to design well written, maintainable programs

  6. Base Conversions Convert 123|10 to Base 10 (gotta start someplace) 1 2 3 |10 = ? |10 | | | | | `--- 3 x 100 = 3 x 1 = 3 | `----- 2 x 101 = 2 x 10 = 20 `------- 1 x 102 = 1 x 100 = 100 123 Therefore, 123|10 = 123|10

  7. Base Conversions Convert 123|8 to Base 10 1 2 3 |8 = ? |10 | | | | | `--- 3 x 80 = 3 x 1 = 3 | `----- 2 x 81 = 2 x 8 = 16 `------- 1 x 82 = 1 x 64 = 64 83 Therefore, 123|8 = 83|10

  8. Base Conversions Convert 123|16 to Base 10 F A C E |16 = ? |10 | | | | | | | `--- E x 160 = 14 x 1 = 14 | | `----- C x 161 = 12 x 16 = 192 | `------- A x 162 = 10 x 256 = 2560 `--------- F x 163 = 15 x 4096 = 61440 64206 Therefore, FACE|16 = 64206|10

  9. Base Conversions Convert 123|10 to Base 8 8 )123 8 )15 R 3 8 )1 R 7 0 R 1 Therefore, 123|10 = 173|8 Base you are converting to Read Up!

  10. Base Conversions Convert 64206|10 to Base 16 16 )64206 16 )4012 R 14 (E) 16 )250 R 12 (C) 16 )15 R 10 (A) 16 )0 R 15 (F) Therefore, 64206|10 = FACE|16 Base you are converting to Read Up!

  11. Step 1: 123|7=?|10 1 2 3 | | | | | `-3x70= 3 | `--2x71=14 `-----1x72=49 66 \ 123|7=66|10 Step 2: 66|10=?|9 9 )66 9 ) 7 R 3 0 R 7 66|10=73|9 123|7=73|9 Base Conversions123|7 = ?|9 (Can’t do directly)

  12. Base Conversions • Converting between bases which are powers of 2 (base 2, 4, 8, and 16) • Each Digit in base 4, 8 or 16 represents 2, 3 or 4 bits

  13. Base Conversions 10101110001101|2=?|8 #10 101 110 001 101 • 2 5 6 1 5 • 10101110001101|2=25615|8 NOTE: # is a place holder for zero Work from right to left Divide into 3 bit groups

  14. Base Conversions 10101110001101|2=?|16 ##10 1011 1000 1101 • 2 B 8 D • 10101110001101|2=2B8D|16 NOTE: # is a place holder for zero Work from right to left Divide into 4 bit groups

  15. Base Conversions 1357|8=?|2 1 3 5 7 001 011 101 111 \ 1357|8=001011101111|2 Note: one need not write the leading zeros

  16. Base Conversions FACE|16=?|2 F A C E 1111 1010 1100 1110 \ FACE|16=1111101011001110|2

  17. Base Conversions A1CE|16=?|8 2 1 C E 1010000111001110 1 2 0 7 1 6 \A1CE|16=120716|8

  18. Terminology • Bit – a 0 or a 1 • Nibble – 4 bits • Byte – 8 bits • Word – Machine dependent(8086/88 = 16 bits; 386/486/Pent = 32 bits) • Doubleword – Machine dependent(8086/88 = 32 bits; 386/486/Pent = 64 bits)

  19. Terminology • K – Kilo; 210 = 1024 • M – Mega; 220 = 1048576 • G – Giga; 230 = 1073741824 • T – Tera; 240 = 1099511627776

  20. Rough Cost per RAM Disk • K – Kilo; • M – Mega; $ .50 • G – Giga; $ 500. $ 10. • T – Tera; $10,000.

  21. ASCII-American Standard Code for Information Interchange • Used to represent characters • Seven bit code used to represent character • ‘0’ through ‘9’ are characters • IBM used 8 bits in PC and added 128 additional characters (line drawing, Greek) • Problem with ASCII – the A • Unicode addresses this problem

  22. ASCII-points to note • Values 30-39=Chars ‘0’-’9’ • ‘a’ = ‘A’ + 32 (Bit 5) • ‘A’ = Ctrl/A+64 (bit 6) • ‘A’ < ‘Z’ < ‘a’ < ‘z’ • If character is represented in a byte, bit 7 is usually 0 • Chars 0-31d are not printable, but may influence how other chars are printed.

  23. Binary Addition 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 (with carry of 1)

  24. 1011011 + 10110 = ? 1 0 1 1 0 1 1 + 1 0 1 1 0 ---------------- 1 1 1 0 0 0 1

  25. 100111001 + 11011 = ?

  26. 100111001 + 11011 = ? 1 0 0 1 1 1 0 0 1 + 1 1 0 1 1 -----------------

  27. 100111001 + 11011 = ? 1 0 0 1 1 1 0 0 1 + 1 1 0 1 1 ----------------- 1 0 1 0 1 0 1 0 0

  28. 4BA978 + D2B84 58D4FC 8+4=C 7+8=F 9+B=4 w/ carry 1+A+2=D B+D=8 w/ carry 1+4+0=5 Hex Addition

  29. Hex Addition Table

  30. Positive/Negative Numbers 1100 1110 0000 0010 0100 1011 1101 1111 0001 0011 0101 -5 -4 -3 -2 -1 0 1 2 3 4 5 Notes • We are in “4-bit” mode • Think odometer math (-1=1111, -2=1110,-3=1101, -4=1100, -5=1011, -6=1010, etc.) • At some point a big positive number+1 becomes a big negative number • Really a number “circle”

  31. 4-bit Number Circle 0000 1111 0001 0 1110 -1 1 0010 -2 2 1101 0011 -3 3 1100 -4 4 0100 -5 5 1011 0101 -6 6 -7 7 0110 1010 -8 1001 0111 1000

  32. Observations (Part 1) 0110 6+ 0011 + 31001 9ûû 0100 40010 + 20110 6üü 0110 61101 +-310011 3üü 1010 -61101 +-310001 9ûû 1100 -41110 +-211010 -6üü 1010 -60011 + 31101 -3üü

  33. Observations (Part 2) 0110 6+ 0011 + 31001 9ûû 0100 40010 + 20110 6üü 0110 61101 +-310011 3üü 1010 -61101 +-310001 9ûû 1100 -41110 +-211010 -6üü 1010 -60011 + 31101 -3üü

  34. Observations (Part 3) & Conclusions • Note when a carry into the sign bit occurs • Note when a carry out of the sign bit occurs • If one occurs and not the other – WRONG • If both occur – RIGHT • If neither occur – RIGHT • Therefore: OF = carry into sign bit carry out of sign bit

  35. Organization of a computer Address Bus CPU RAM ROM Printer Disk CRT Kbd Data Bus Control Bus

More Related