Download Computer Logic and Architecture

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Computer program wikipedia , lookup

Manchester Mark 1 wikipedia , lookup

Computer science wikipedia , lookup

Transcript
Internal Information Representation and Processing
CSCE 106 - Fundamentals of Computer Science
Dr. Awad Khalil
Computer Science & Engineering Department
The American University in Cairo
Decimal Number System
 We are used to the decimal number system which is a positional number system
 The decimal number 4386 represents the value: 41000 + 3  100 + 8  10 + 6  1
 In general, the decimal number dn dn-1 . . . d1 d0 represents the value:
d n  10  d n1  10
n
n 1
n
 ...  d1  10  d 0  10   di  10i
1
0
i 0




The digit at the left is called the most significant digit
The most significant digit has the largest power of ten
The digit at the right is called the least significant digit
The concept of zero is a cornerstone in the decimal number system. It enables us to
multiply by 10 by simply adding a zero as a least significant digit.
 Similarly, we can divide by zero by remove the least significant zero or inserting a
decimal point.
1234  10 = 12340
Internal Information Representation - slide 1
1234 / 10 = 123.4
Fundamentals of Computer Science – Awad Khalil
Other Radices
 The positional number system is called also the Arabic number system (the Arabs
have discovered the 0)
 Other bases (called also radices) are possible
 A digit in base b is between 0 and b-1
 Base 10 digits: 0, 1, …, 9 (called also decimal digits)
 Base 2 digits: 0 and 1 (called also binary digits or bits)
 Base 3 digits: 0, 1, 2
 Base 8 digits: 0, 1, …, 7 (called also octal digits)
 Base 16 digits: 0, 1, …, 9, A, B, C, D, E, F (called also hexadecimal digits)
 The number (dn dn-1 . . . d1 d0)b represents the value:
n
d n  b n  d n 1  b n 1  ...  d1  b1  d 0  b 0   d i  b i
i 0
 Examples:
(207)8 = 2  82 + 0  81 + 7  80 = 128 + 0 + 7 = 135
(1011)2 = 1  23 + 0  22 + 1  21 + 1  20 = 8 + 0 + 2 + 1 = 11
Internal Information Representation - slide 2
Fundamentals of Computer Science – Awad Khalil
Binary, Octal, and Hexadecimal Number Systems
 Computers use the binary number system
 Two binary digits: 0 and 1 called bits
 In the hardware circuitry, 0 represents LOW voltage, while 1 represents HIGH voltage
 Information inside the computer is represented by 0’s and 1’s
 The integer values 0 to 16, represented in four number systems are shown below:
Decimal
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Binary
0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111
10000
Octal
Hexadecimal
0
1
2
3
4
5
6
7
10
11
12
13
14
15
16
17
20
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
10
Internal Information Representation - slide 3
 Advantages of the octal and hexadecimal
numbers:
 Reduce the length of numbers
 Are more readable than binary numbers
 Can be easily converted to/from binary
Fundamentals of Computer Science – Awad Khalil
Conversions between Number Systems
 A number in base b can be easily converted to base 10 using the following equation:
n
d n  b n  d n 1  b n 1  ...  d1  b1  d 0  b 0   d i  b i
i 0
3
2
1
0
 Examples: (2012)3 = 2  3 + 0  3 + 1  3 + 2  3 = 54 + 0 + 3 + 2 = 59
(A0F)16 = 10  162 + 0  161 + 15  160 = 2560 + 0 + 15 = 2575
 We can also convert a decimal number N to obtain the number (dn dn-1 . . . d1 d0 )b in
base b using the following algorithm:
i := 0;
Question: Convert 50 to base 2
Question: Convert 50 to base 3
q := N;
Answer:
Answer:
d0 = 50 mod 2 = 0, q = 50 div 2 = 25
d0 = 50 mod 3 = 2, q = 50 div 3 = 16
repeat
mod 2 = 1, q = 25 div 2 = 12
d1 = 16 mod 3 = 1, q = 16 div 3 = 5
di := q mod b; dd1 == 25
12 mod 2 = 0, q = 12 div 2 = 6
d2 = 5 mod 3 = 2,
q = 5 div 3 = 1
2
q := q div b;
d3 = 6 mod 2 = 0,
q = 6 div 2 = 3
d3 = 1 mod 3 = 1,
q = 1 div 3 = 0
d4 = 3 mod 2 = 1,
q = 3 div 2 = 1
i := i + 1;
d5 = 1 mod 2 = 1,
q = 1 div 2 = 0
Thus, 50 = (1212)3
until q = 0;
Thus, 50 = (110010)2
Internal Information Representation - slide 4
Fundamentals of Computer Science – Awad Khalil
More Conversions
 Suppose we want to convert a number from base 3 to base 2, we can convert it first to base 10
and then to base 2
 Example: Convert (1012)3 to base 2
Answer:
(1012)3 = 1  33 + 0  32 + 1  31 + 2  30 = 27 + 3 + 2 = 32
d0 = 32 mod 2 = 0, q = 32 div 2 = 16
d1 = 16 mod 2 = 0, q = 16 div 2 = 8
d2 = 8 mod 2 = 0,
q = 8 div 2 = 4
d3 = 4 mod 2 = 0,
q = 4 div 2 = 2
d4 = 2 mod 2 = 0,
q = 2 div 2 = 1
d5 = 1 mod 2 = 1,
q = 1 div 2 = 0
Thus, (1012)3 = 32 = (100000)2
 It is easy to convert numbers between the binary, octal, and hexadecimal systems
 Every 3 binary digits can be converted into an octal digit starting at the least significant bit
 Every 4 binary digits can be converted into a hexadecimal digit
 Example: (10100110)2 = (246)8 = (A6)16
Internal Information Representation - slide 5
Fundamentals of Computer Science – Awad Khalil
Computer Representation of Information
 Basic unit of information is the Bit or Binary digit.
 With a single bit, we can represent two distinct values 0 and 1.
 With two bits, we can represent four distinct values: 00, 01, 10, and 11.
 In general, with m bits, we can represent 2m distinct values.
 A byte is a grouping of 8 bits.
 A word is a grouping of either 16, 32, or 64 bits, depending on the computer system.
 A word is typically 32 bits on most systems, a half word is 16 bits, and a double word
is 64 bits.
Bit = 0 or 1
Byte = 8 bits
Half Word = 2 bytes = 16 bits
Word = 4 bytes = 32 bits
Long Word = 8 bytes = 64 bits
Internal Information Representation - slide 6
Fundamentals of Computer Science – Awad Khalil
Binary Addition
 The addition of 3 bits a + b + c produces a sum bit and a carry bit.
 Signed Integers are represented in 2’s complement notation.
 Addition of integers in 2’s complement notation results in a signed integer.
 Although a carry out is produced in the 2nd and 4th computations, it is ignored.
Examples:
carry 
a b c
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
a+b+c
carry sum
0
0
0
1
0
1
1
1
0
1
1
0
1
0
0
1
01001101 +77
+ 00101011 +43
sum 
carry 
01111000 +120
11110
11001101 –51
+ 00101011 +43
sum 
Internal Information Representation - slide 7
carry 
11110
11111000
–8
111011000
11101101
+ 10101110
sum 
10011011
carry 
111011000
–19
–82
–101
01101101 +109
+ 10101110
–82
sum 
00011011
Fundamentals of Computer Science – Awad Khalil
+27
The Discipline of Computing
 Computing is a relatively young academic discipline.
 We distinguish between applications of the computer within other disciplines such as
business, engineering, and sciences, and the nature of computing itself.
 Peter Denning gave the following broad definition of the field of Computer Science:
Computer Science is the body of knowledge dealing with the design, analysis,
implementation, efficiency, and application of processes that transform
information. The fundamental question underlying all of computer science is "what
can be automated?"
 Nine general subject areas combine to make up the discipline of Computing. These are
shown below:
Internal Information Representation - slide 8
Fundamentals of Computer Science – Awad Khalil
The Discipline of Computing
Artificial
Intelligence
Numeric and Symbolic
Computation
Algorithms and
Data Structures
Programming
Languages
Database
Systems
Software
Engineering
Computer
Architecture
Operating
Systems
Human-Computer
Communication
Internal Information Representation - slide 9
Fundamentals of Computer Science – Awad Khalil