Download presentation
Presentation is loading. Please wait.
Published byKerry Warren Modified over 9 years ago
1
Computer Programming I
2
Today’s Lecture Components of a computer Program Programming language Binary representation
3
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 1-3 Computer Components Hardware CPU IO device Main memory Software How does computer work?
4
Computer Components
5
The Central Processing Unit “brain” of the computer.
6
Memory Random Access Memory (RAM) Temporary memory Main memory Read Only Memory (ROM) For start-up directions permanent memory.
7
The execution speed of a program depends on CPU RAM Why?
8
Programs Computer Hardware Software Programs that run on a computer Operating system Application software
9
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 1-9 Programming Languages Three types of programming languages 1. Machine languages Strings of numbers giving machine specific instructions Example: +1300042774 +1400593419 +1200274027
10
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 1-10 Programming Languages Three types of programming languages 2. Assembly languages English-like abbreviations representing elementary computer operations (translated via assemblers) Example: LOAD BASEPAY ADD OVERPAY STORE GROSSPAY
11
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 1-11 Programming Languages Three types of programming languages 3. High-level languages Codes similar to everyday English Use mathematical notations (translated via compilers) Example: grossPay = basePay + overTimePay
12
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 1-12 Programming Languages (3) Machine Languages Assembly Languages High-Level Languages +1300042774 +1400593419 +1200274027 LOAD A ADD B STORE C C=A+B
13
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 1-13 C++ C++ is a third generation language Why C++ not C C++ is an object oriented language
14
Decimal System Positional base 10 numeral systems 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Use same symbol for different orders of magnitude For example, “1262” in base 10 1*10 3 +2*10 2 +6*10 1 +2*10 0
15
Binary A computer is a “bistable” device A bistable device: Easy to design and build Has 2 states: 0 and 1 One Binary digit (bit) represents 2 possible states (0, 1)
16
Bits With 2 bits, 4 states are possible (2 2 = 4) Bit 1 Bit 0 State 00 1 01 2 10 3 11 4
17
Decimal to Binary representation 0: 0 1: 1 2: 10 3: 11 4: 100 5: 101 6: 110 7: 111 8: 1000 9: 1001 10: 1010 11: 1011 12: 1100 13: 1101 14: 1110 15: 1111 16: 10000 17: 10001
18
Convert Binary to Decimal 18 Interpret binary numbers (transform to base 10) 1101 = 1*2 3 +1*2 2 +0*2 1 +1*2 0 =8+4+0+1=13 Translate the following binary number to decimal number 101011
19
Convert Decimal to Binary Procedure: 1. Divide the decimal number by 2 2. Make the remainder the next digit to the left of the answer 3. Replace the decimal number with the quotient 4. If quotient is not zero, Repeat 1-4; otherwise, done
20
Algorithm A finite set of well-defined instructions for accomplishing some task which, given an initial state, will terminate in a corresponding recognizable end-state. Examples: Select the largest number from a set of number (n) Suppose n numbers are a1, a2, …an Set LG=a1; For i=2 to n, do if LG<ai, then set LG=ai; Else do nothing; The largest number is LG
21
Convert Decimal number 100 to Binary Number 100 % 2 = 0=> last digit 100 / 2 = 50 50 % 2 = 0=> 2 nd last digit 50/2 = 25 25 % 2 = 1=> 3rd last digit 25 / 2 = 12 12 % 2 = 0=> 4th last digit 12 / 2 = 6 6 % 2 = 0 => 5 th last digit 6 / 2 = 3 3 % 2 = 1 => 6 th last digit 3 / 2 =1 1 % 2 = 1 => 7 th last digit 1 / 2 = 0 The result is 1100100
22
Convert Decimal Number 1492 to Binary Number
23
Bytes and Words A group of 8 bits is a byte A byte can represent 2 8 = 256 possible states Several bytes grouped together to form a word Word length of a computer, e.g., 32 bits computer, 64 bits computer
24
Memory Size Metrics 1KB = 1024 bytes 1MB = 1024 x 1024 bytes 1GB = 1024 x 1024 x 1024 bytes
25
Representing Text Text is a series of characters letters, punctuation marks, digits 0, 1, …9, spaces, return (change a line),… How many bits do we need to represent a character? 1 bit can be used to represent 2 different things 2 bit … 2*2 = 2 2 different things n bit 2 n different things In order to represent 128 different character Solve 2 n = 128 for n n=7
26
ASCII The American Standard Code for Information Interchange 128 characters 7 bits could be used to represent ASCII characters However, in 1960s, an 8-bit byte was becoming hardware standard, therefore, it was decided to use 1 byte (8 bits) to store the ASCII code (first 7 bits), with the eighth bit being used as a parity bit to detect transmission errors
27
ASCII Table
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.