COE221 Lect2 Numbersystems 2s
COE221 Lect2 Numbersystems 2s
Now What?
Mon Sep 16 24 Oct 1 8 15 22 29 Nov 5 12 19 26
COE221: Digital Systems Dr. Fadi Aloul
Wed 18 26 3 10 17 24 31 7 14 21 28 1 2 3 4 5 6 7 8 9 10 11
American University of Sharjah Page 2
Introduction Number Systems and Codes Boolean Algebra & Logic Circ. Midterm Exam #1 Simplification of Switching Fcn. Modular Combinational Logic Introduction to Sequential Dev. Midterm Exam #2 M d l S Modular Sequential ti l L Logic i Memory and Prog. Logic Final Exam
Arabic
English
Decimal
Octal
French
Spanish
Binary
HexaDecimal
Multiple Languages
Arabic
English
French
Used in the France
Spanish
Used in Mexico
Used by Humans
Decimal
Octal
Used by ???
Binary
Used by Computers
HexaDecimal
Used by ???
Decimal System
Decimal system composed of 10 numerals or symbols
0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Known as Base 10 or Radix 10, since it has 10 numbers
Example
9735 = 9000 + 700 + 30 + 5 = 9 x 1000 + 7 x 100 + 3 x 10 + 5 = 9 x 103 + 7 x 102 + 3 x 101 + 5 x 100 2745.214 = 2 x 103 + 7 x 102 + 4 x 101 + 5 x 100 + 2 x 10-1 + 1 x 10-2 + 4 x 10-3
Coefficient Base
Binary System
Unfortunately, decimal number system is not convenient for digital system implementations
Imagine electrical equipment working with 10 different levels of voltage Much easier with two voltages only
Example
1011.1012 = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 + 1 x 2-1 + 0 x 2-2 + 1 x 2-3 = 8 + 0 + 2 + 1 + 0.5 + 0 + 0.125 = 11.62510
COE221: Digital Systems Dr. Fadi Aloul American University of Sharjah Page 7
Decimal Counting
000 001 002 003 004 005 006 007 008 009
010 011 012 013 014 015 016 017 018 019
020 021 022 023 024 025 026 027 028 029
090 091 092 093 094 095 096 097 098 099
100 101 102 103 104 105 106 107 108 109
Binary Counting
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
COE221: Digital Systems Dr. Fadi Aloul
What is the largest number that can be represented with 4 bits? 2N (N is the number of bits) = 24 = 16
Binary Counting
0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 10 1011 11 1100 12 1101 13 1110 14 1111 15
Binary Numbers
Decimal Numbers
What is the largest number that can be represented with 4 bits? 2N (N is the number of bits) = 24 = 16
Exercise
Convert 1001.102 to decimal
Exercise
Convert 3710 to binary
1 1 1 0 1
Decimal
Binary
Octal System
Often used in digital computer work Octal system composed of 8 numerals or symbols
0, 1, 2, 3, 4, 5, 6, 7 Known as Base 8 or Radix 8, since it has 8 numbers
4 1 2
Decimal
Binary Octal
Hexadecimal System
Hex system composed of 16 numerals or symbols
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Known as Base 16 or Radix 16, since it has 16 numbers
E A
Decimal
Number Relationships
Decimal
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
COE221: Digital Systems Dr. Fadi Aloul
Binary
0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111
Octal
0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17
Hexadecimal
0 1 2 3 4 5 6 7 8 9 A B C D E F
American University of Sharjah Page 20
10
Hexadecimal
Convert from Binary to Hexadecimal (0010101100110)2 = 0 0101 0110 0110 0000 0101 0110 0110 0 5 6 6 (0566)16
Hexadecimal
11
Example
11012 = (??) 3 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 = 8+4+0+1 Number Quotient Remainder = 1310 13 / 3 4 1 1310 = 1113 4/3 1 1 1/3 0 1 1 1 1
COE221: Digital Systems Dr. Fadi Aloul American University of Sharjah Page 23
Difficult to memorize
Easier to memorize
Easier to memorize
American University of Sharjah Page 24
12
1 0 1 1
Hexadecimal
Convert from Binary to Hexadecimal (0010101100.110)2 = 00 1010 1100 . 110 0000 1010 1100 . 1100 0 A C. C (0AC.C)16
13
Binary Addition
Similar to Decimal addition
0 + 0 = 00 0 + 1 = 01 1 + 1 = 10
Signed Numbers
Digital systems handle positive and negative numbers
Need to be able to represent sign
14
Not preferred
+2 +3 -3 -2 -1 -0
1s Complement
Flip each bit in binary number (includes sign bit)
0 -> 1 1 -> 0 +0 000 001 010 011 100 101 110 111
American University of Sharjah Page 30
Not preferred
+1 +2 +3 -3 -2 -1 -0
15
2s Complement
Another way of representing negative numbers
Positive numbers represented normally Negative numbers two steps Flip Fli each h bit (find (fi d 1st complement) l t) Add a 1 (ignore overflow) Sign bit within the 7 bits
Example
Represent (-45)10 in 2s complement system 0101101 1010010 + 1 -------------1010011 (45) flip [find 1st complement] add 1 0 101101 1 010011 + 45 - 45
2s Complement
Preferred Allows the user to perform subtraction by actually performing addition! Great! ... Will see that later
Use same hardware for subtraction and addition Save hardware! +0 +1 +2 +3 -3 -2 -1 -0
COE221: Digital Systems Dr. Fadi Aloul
16
Signed Numbers
Exercise
Find (-20)10 using: sign magnitude, 1st complement 2nd complement Convert (33)10 to binary in less than 5 seconds [counting hint]
2s Complement
Must include of sign bit Example p
1000 0111 + 1 -------------1000 01000 10111 + 1 -------------11000
COE221: Digital Systems Dr. Fadi Aloul
2s complement of original binary number (8) Better! 01000 represents 8 st 11000 represents -8 flip [find 1 complement] add 1 2s complement of original binary number
American University of Sharjah Page 34
17
Example
Represent (-45)10 in 2s complement system using 8 bits 00101101 11010011 (45) 2s complement of original binary number
18
Range of Numbers
An N-bit number
Unsigned : 0 2N -1 Signed : -2N-1 +1 2N-1 -1
Example - 3 bit
Unsigned : 0 7 Signed : -3 3
Unsigned numbers 000 (0) 111 (7)
101 (-3)
011 (3)
Signed numbers
COE221: Digital Systems Dr. Fadi Aloul American University of Sharjah Page 37
19
20
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
BCD
(0110100000111001)bcd
Binary
(1101010110111)2 Complex conversion to Decimal Simpler Circuits Efficient encoding
21
BCD Arithmetic
Rules:
Ordinary Binary addition If sum is <= 9, done If sum > 9, add 0110 carry is taken to next position
Example
6 0110 +7 0111 --------------13 1101
Example
6 0110 +3 0011 --------------9 1001 + 0110 add 6 for correction --------------- ( (count skipped pp # #s) ) 0001 0011 1 3
BCD Arithmetic
Example
47 0100 0111 +35 0011 0101 ------------------------82 0111 1100 0110 ------------------------1000 0010 8 2
Example
59 0101 1001 +38 0011 1000 ------------------------97 1001 0001 0110 ------------------------1001 0111 9 7
Sum is 10001
22
ASCII Code
American Standard Code for Information Interchange Consists of 7-bit code
27 = 128 possible codes
Example
Character A B $ = ASCII 100 0001 100 0010 010 0100 011 1101 Octal 101 102 044 075 Hex 41 42 24 3D
Now What?
Mon Sep 16 24 Oct 1 8 15 22 29 Nov 5 12 19 26
COE221: Digital Systems Dr. Fadi Aloul
Wed 18 26 3 10 17 24 31 7 14 21 28 1 2 3 4 5 6 7 8 9 10 11
American University of Sharjah Page 46
Introduction Number Systems and Codes Boolean Algebra & Logic Circ. Midterm Exam #1 Simplification of Switching Fcn. Modular Combinational Logic Introduction to Sequential Dev. Midterm Exam #2 M d l S Modular Sequential ti l L Logic i Memory and Prog. Logic Final Exam
23