Title: ECE 160 Comp Programming I Data Structures with C
1ECE 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/ece1
60/ece160.htm - Book C for Engineers and Scientists
- An Introduction to Programming with ANSI C
- Gary J. Bronson (EditorMixer)
- West Publishing
2Tentative 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
3Working 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.
4Canceled 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
5Course 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
6Base Conversions
- Convert 12310 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, 12310 12310
7Base Conversions
- Convert 1238 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, 1238 8310
8Base Conversions
- Convert 12316 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, FACE16 6420610
9Base Conversions
Convert 12310 to Base 8 8 )123 8 )15 R 3
8 )1 R 7 0 R 1 Therefore, 12310
1738
Base you are converting to
Read Up!
10Base Conversions
Convert 6420610 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, 6420610
FACE16
Base you are converting to
Read Up!
11Base Conversions1237 ?9 (Cant do directly)
- Step 1 1237?10
- 1 2 3
-
- -3x70 3
- --2x7114
- -----1x7249
- 66
- \ 12376610
- Step 2 6610?9
- 9 )66
- 9 ) 7 R 3
- 0 R 7
- 6610739
- 1237739
12Base 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
13Base Conversions
- 101011100011012?8
- 10 101 110 001 101
- 2 5 6 1 5
- 101011100011012256158
- NOTE is a place holder for zero
Work from right to left Divide into 3 bit groups
14Base Conversions
- 101011100011012?16
- 10 1011 1000 1101
- 2 B 8 D
- 1010111000110122B8D16
- NOTE is a place holder for zero
Work from right to left Divide into 4 bit groups
15Base Conversions
- 13578?2
- 1 3 5 7
- 001 011 101 111
- \ 135780010111011112
Note one need not write the leading zeros
16Base Conversions
- FACE16?2
- F A C E
- 1111 1010 1100 1110
- \ FACE1611111010110011102
17Base Conversions
- A1CE16?8
- 2 1 C E
- 1010000111001110
- 1 2 0 7 1 6
- \A1CE161207168
18Terminology
- 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)
19Terminology
- K Kilo 210 1024
- M Mega 220 1048576
- G Giga 230 1073741824
- T Tera 240 1099511627776
20Rough Cost per
- RAM Disk
- K Kilo
- M Mega .50
- G Giga 500. 10.
- T Tera 10,000.
21ASCII-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-39Chars 0-9
- a A 32 (Bit 5)
- A Ctrl/A64 (bit 6)
- A lt Z lt a lt 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.
23Binary 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
28Hex Addition
- 84C
- 78F
- 9B4 w/ carry
- 1A2D
- BD8 w/ carry
- 1405
29Hex Addition Table
30Positive/Negative Numbers
0000
0010
0100
1100
1110
0001
0011
0101
1011
1111
1101
0
1
2
3
4
5
-5
-4
-2
-1
-3
- Notes
- We are in 4-bit mode
- Think odometer math (-11111, -21110,-31101,
-41100, -51011, -61010, etc.) - At some point a big positive number1 becomes a
big negative number - Really a number circle
314-bit Number Circle
0000
1111
0001
0
1110
-1
1
0010
2
-2
1101
0011
-3
3
0100
1100
4
-4
-5
5
0101
1011
-6
6
7
-7
0110
1010
-8
1001
0111
1000
32Observations (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 üü
33Observations (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 üü
34Observations (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
35Organization of a computer
Address Bus
CPU RAM ROM Printer Disk
CRT Kbd
Data Bus
Control Bus