ee2174: digital logic and lab
DESCRIPTION
EE2174: Digital Logic and Lab. Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 2 Number System. Overview. Digital Computers Number Systems Representations Conversions Arithmetic Operations Decimal Codes Alphanumeric Codes. - PowerPoint PPT PresentationTRANSCRIPT
EE2174: Digital Logic EE2174: Digital Logic and Laband Lab
Professor Shiyan HuProfessor Shiyan Hu
Department of Electrical and Computer Department of Electrical and Computer EngineeringEngineering
Michigan Technological UniversityMichigan Technological University
CHAPTER 2CHAPTER 2
Number SystemNumber System
Apr 20, 2023
PJF - 2Chapter 1: Digital Computers and Information
OverviewOverview
Digital ComputersDigital Computers Number SystemsNumber Systems
RepresentationsRepresentations ConversionsConversions
Arithmetic OperationsArithmetic Operations Decimal CodesDecimal Codes Alphanumeric CodesAlphanumeric Codes
Apr 20, 2023
PJF - 3Chapter 1: Digital Computers and Information
Digital SystemsDigital Systems
Major characteristicMajor characteristic manipulation of manipulation of discretediscrete elements of elements of
information (any set restricted to a finite information (any set restricted to a finite # of elements)# of elements)
e.g. 10 decimal digits, 26 letterse.g. 10 decimal digits, 26 letters Discrete elements (in digital Discrete elements (in digital
systems) can be represented by systems) can be represented by signalssignals (physical quantities). (physical quantities). Most common signals: electrical Most common signals: electrical
(voltage, current)(voltage, current)
Apr 20, 2023
PJF - 4Chapter 1: Digital Computers and Information
Voltage RangesVoltage RangesThe 2 binary values (HIGH, LOW) of a digital signal are The 2 binary values (HIGH, LOW) of a digital signal are represented by represented by rangesranges of voltage values of voltage values
Apr 20, 2023
PJF - 5Chapter 1: Digital Computers and Information
Information RepresentationInformation Representation
Binary signals (2 discrete values)Binary signals (2 discrete values) 0 and 1 (LOW and HIGH, FALSE and 0 and 1 (LOW and HIGH, FALSE and
TRUE)TRUE) Binary quantity: binary digit/bitBinary quantity: binary digit/bit Information: group of bits/words (size: 8, Information: group of bits/words (size: 8,
16, 32, 64, …)16, 32, 64, …) Digital hardware computes Digital hardware computes binary binary
functionsfunctions of of binary numbers:binary numbers: Combinational (memoryless)Combinational (memoryless) Sequential (using memory)Sequential (using memory)
Apr 20, 2023
PJF - 6Chapter 1: Digital Computers and Information
Number SystemsNumber Systems
Representation of numbersRepresentation of numbers Radix: “base”, the primitive unit for Radix: “base”, the primitive unit for
group of numbers, e.g. for decimal group of numbers, e.g. for decimal arithmetic radix=10 (“base” 10)arithmetic radix=10 (“base” 10)
For every system, we need For every system, we need arithmetic operations (addition, arithmetic operations (addition, subtraction, multiplication)subtraction, multiplication)
Also, conversion from one base to Also, conversion from one base to the otherthe other
Apr 20, 2023
PJF - 7Chapter 1: Digital Computers and Information
Number Systems - DecimalNumber Systems - Decimal
““base” 10 (radix is 10)base” 10 (radix is 10) 10 digits: 0..910 digits: 0..9 ((251.3251.3))1010 = = 2210102 2 + + 5510101 1 + + 1110100 0 + +
331010-1-1
Note: ‘.’ is called the Note: ‘.’ is called the radix pointradix point (decimal point for base 10)(decimal point for base 10)
Apr 20, 2023
PJF - 8Chapter 1: Digital Computers and Information
Number Systems – Decimal Number Systems – Decimal (cont.)(cont.)
In general, a decimal number with In general, a decimal number with nn digits digits to the left of the decimal point, and to the left of the decimal point, and mm digits to the right of the decimal point is digits to the right of the decimal point is written as:written as:
AAn-1n-1 A An-2n-2 … A … A11 A A00 . A . A-1-1 A A-2-2 … A … A-m+1-m+1 A A-m-m
where Awhere Aii is a coefficient between 0..9, is a coefficient between 0..9,
and i denotes the and i denotes the weightweight (=10 (=10ii) of A) of Aii..
Apr 20, 2023
PJF - 9Chapter 1: Digital Computers and Information
Number Systems – Decimal Number Systems – Decimal (cont.)(cont.)
The value of The value of
AAn-1n-1 A An-2n-2 … A … A11 A A00 . A . A-1-1 A A-2-2 … A … A-m+1-m+1 A A-m-m
is calculated byis calculated by
i=n-1..0i=n-1..0 (A(Aii 10 10i i ) + ) + i=-m..-1i=-m..-1 (A(Aii 10 10i i ) )
Apr 20, 2023
PJF - 10Chapter 1: Digital Computers and Information
Number Systems – GeneralNumber Systems – General
““base” base” rr (radix (radix rr)) rr digits digits NN = A = An-1 n-1 rr n-1 n-1 + A+ An-2n-2rr n-2n-2 +… + A +… + A11rr + +
AA00 + +
AA-1 -1 rr -1-1 + A + A-2-2rr -2-2 +… + A +… + A-m -m rr -m-m
MostSignificant Bit (MSB)
LeastSignificantBit (LSB)
Apr 20, 2023
PJF - 11Chapter 1: Digital Computers and Information
Number Systems – General Number Systems – General (cont.)(cont.)
e.g. let e.g. let rr = 8 = 8
(312.5)(312.5)88 = 3= 3882 2 + + 11881 1 + + 22880 0 + + 5588--
11
= (202.625)= (202.625)1010
Conversion from Conversion from nn-ary (any -ary (any system with radix system with radix nn) to decimal ) to decimal follows similar process as abovefollows similar process as above
Apr 20, 2023
PJF - 12Chapter 1: Digital Computers and Information
Number Systems (cont.)Number Systems (cont.)
Most common number systems for Most common number systems for computers:computers: Binary (Binary (rr = 2) = 2) Octal (Octal (rr = 8) = 8) Hexadecimal (Hexadecimal (rr = 16) = 16)
Apr 20, 2023
PJF - 13Chapter 1: Digital Computers and Information
Binary Numbers-Base 2Binary Numbers-Base 2
Computers represent all data as “Computers represent all data as “strings strings of bits”, of bits”, each bit being either 0 or 1each bit being either 0 or 1
““base” 2, with 2 digits: 0 and 1base” 2, with 2 digits: 0 and 1 e.g. e.g.
(101101.10)(101101.10)22 = = 11225 5 + 0+ 0224 4 + + 11223 3 + + 112222 + 0+ 0221 1 + + 112200 + + 1122-1-1 + + 0022-2-2
(in decimal) = 32 + 0 + 8 + 4 + 0 + 1 + ½ + (in decimal) = 32 + 0 + 8 + 4 + 0 + 1 + ½ + 00
= (45.5)= (45.5)1010
Apr 20, 2023
PJF - 14Chapter 1: Digital Computers and Information
Binary Numbers-Base 2 Binary Numbers-Base 2 (cont.)(cont.)
e.g. e.g.
(1001.011)(1001.011)22 = = 11223 3 + + 00222 2 + + 00221 1 + + 112200 + + 0022-1-1 + + 1122-2-2 + +
1122-3-3
(in decimal) = 8 + 1 + 0.25 + 0.125(in decimal) = 8 + 1 + 0.25 + 0.125
= (9.375)= (9.375)1010
Apr 20, 2023
PJF - 15Chapter 1: Digital Computers and Information
Powers of twoPowers of two
Memorize at least through 216
Apr 20, 2023
PJF - 16Chapter 1: Digital Computers and Information
Octal Numbers-Base 8Octal Numbers-Base 8
““base” 8, with 8 digits: 0..7base” 8, with 8 digits: 0..7 e.g. e.g.
(762)(762)88 = = 77882 2 + 6+ 6881 1 + + 22880 0
(in decimal) = 448 + 48 + 2(in decimal) = 448 + 48 + 2
= (498)= (498)1010
Apr 20, 2023
PJF - 17Chapter 1: Digital Computers and Information
Hexadecimal Numbers-Base Hexadecimal Numbers-Base 1616
rr = 16 = 16 Digits (convention): 0..9, A, B, C, D, E, Digits (convention): 0..9, A, B, C, D, E,
FF A=10, B=11, … , F = 15A=10, B=11, … , F = 15 e.g.e.g.
(3FB)(3FB)1616 = = 3 316162 2 + 15+ 1516161 1 + + 111116160 0
(in decimal) = 768 + 240 + 11(in decimal) = 768 + 240 + 11
= (1019)= (1019)1010
Apr 20, 2023
PJF - 18Chapter 1: Digital Computers and Information
Base ConversionsBase Conversions
Any base Any base rr decimal – Easy! decimal – Easy! (already covered, see slides 13-14, (already covered, see slides 13-14, 16-17, 19-20)16-17, 19-20)
Decimal Decimal Binary Binary Octal Octal Binary Binary Hex Hex Binary Binary Decimal Decimal Any base Any base rr
Apr 20, 2023
PJF - 19Chapter 1: Digital Computers and Information
Decimal to BinaryDecimal to Binary
Let Let NN be a decimal number. be a decimal number.
1.1. Find the Find the greatestgreatest number that is a power of 2 number that is a power of 2 and when subtracted from and when subtracted from NN it produces a it produces a positive difference positive difference NN11
2.2. Put a 1 in the MSBPut a 1 in the MSB
3.3. Repeat Step 1, starting from Repeat Step 1, starting from NN11 and finding and finding difference difference NN22. . Put a 1 in the corresponding bit. Put a 1 in the corresponding bit. Stop when the difference is zero. Stop when the difference is zero.
Apr 20, 2023
PJF - 20Chapter 1: Digital Computers and Information
Decimal to Binary (cont.)Decimal to Binary (cont.)
e.g. e.g. N N = (717)= (717)1010
717 – 512 = 205 = 717 – 512 = 205 = NN11 512 = 2512 = 299
205 –128 = 77 = 205 –128 = 77 = NN22 128 = 2128 = 277
77 – 64 = 13 = 77 – 64 = 13 = NN33 64 = 264 = 266
13 – 8 = 5 = 13 – 8 = 5 = NN44 8 = 2 8 = 233
5 – 4 = 1 = 5 – 4 = 1 = NN55 4 = 2 4 = 222
1 – 1 = 0 = 1 – 1 = 0 = NN66 1 = 21 = 200
(717)(717)1010 = 2 = 299 + 2 + 277 + 2 + 266 + 2 + 233 + 2 + 222 + 2 + 200 = ( 1 0 1 1 0 0 1 1 0 1)= ( 1 0 1 1 0 0 1 1 0 1)22
Apr 20, 2023
PJF - 21Chapter 1: Digital Computers and Information
Binary to Octal and HexBinary to Octal and Hex
Octal:Octal:
8 = 28 = 233 every 3 binary bits convert 1 every 3 binary bits convert 1 octaloctal
Hex:Hex:
16 = 216 = 244 every 4 binary bits convert 1 every 4 binary bits convert 1 hexhex
Apr 20, 2023
PJF - 22Chapter 1: Digital Computers and Information
Binary Binary Octal Octal
(011 010 101 000 . 111 101 011 100)2
( 3 2 5 0 . 7 5 3 4 )8
Apr 20, 2023
PJF - 23Chapter 1: Digital Computers and Information
Binary Binary Hex Hex
( 6 A 8 . F 5 C )16
( 0110 1010 1000 . 1111 0101 1100 )2
Apr 20, 2023
PJF - 24Chapter 1: Digital Computers and Information
Octal Octal Hex Hex
Go through Binary!
Hex Binary OctalOctal Binary Hex
Apr 20, 2023
PJF - 25Chapter 1: Digital Computers and Information
Convert Decimal to any Convert Decimal to any base base rr
Integer part:Integer part: Divide by the base, keep Divide by the base, keep track of remainder, and read-uptrack of remainder, and read-up
e.g. (153)e.g. (153)1010 = ( ? ) = ( ? )88 , , r = 8r = 8153 / 8153 / 8 = 19 + 1/8 = 19 + 1/8 rem = 1rem = 1 LSB LSB 19 / 8 = 2 + 3/819 / 8 = 2 + 3/8 rem = 3rem = 3
2 / 8 = 2 / 8 = 00 + 2/8 + 2/8 rem = 2 MSBrem = 2 MSB
(153)(153)1010 = ( 231) = ( 231)88
stopstop
Apr 20, 2023
PJF - 26Chapter 1: Digital Computers and Information
Convert Decimal to any Convert Decimal to any base base rr
Fractional part:Fractional part: Multiply by the base, keep Multiply by the base, keep track of integer part, and read-downtrack of integer part, and read-down
e.g. (0.78125)e.g. (0.78125)1010 = ( ? ) = ( ? )1616 , , r = 16r = 16
0.781250.7812516 = 12.5 integer = 12 = C16 = 12.5 integer = 12 = C MSBMSB
0.5 0.5 16 = 8. 16 = 8.00 integer = 8 = 8 LSB integer = 8 = 8 LSB
(0.78125)(0.78125)1010 = (0.C8) = (0.C8)1616 stopstop
Apr 20, 2023
PJF - 27Chapter 1: Digital Computers and Information
Binary Arithmetic Operations:Binary Arithmetic Operations:AdditionAddition
Follow same rules as in decimal addition, Follow same rules as in decimal addition, with the difference that when sum is 2 with the difference that when sum is 2 indicates a carry (not a 10)indicates a carry (not a 10)
Learn new carry rulesLearn new carry rules 0+0 = 0c0 (sum 0 with carry 0)0+0 = 0c0 (sum 0 with carry 0) 0+1 = 1+0 = 1c00+1 = 1+0 = 1c0 1+1 = 0c11+1 = 0c1 1+1+1 = 1c11+1+1 = 1c1
CarryCarry 11 11 11 11 11 00
AugendAugend 00 00 11 00 00 11
AddendAddend 00 11 11 11 11 11
ResultResult 11 00 11 00 00 00
Apr 20, 2023
PJF - 28Chapter 1: Digital Computers and Information
Binary Arithmetic Operations:Binary Arithmetic Operations:Addition (cont.)Addition (cont.)
““Half addition” (rightmost bit position, Half addition” (rightmost bit position, aka LSB): only 2 bits are added, yielding aka LSB): only 2 bits are added, yielding a sum and a carrya sum and a carry
““Full addition” (remaining positions): Full addition” (remaining positions): three bits are added, yielding a sum and three bits are added, yielding a sum and a carrya carry
In Chapter 3, we’ll see many different In Chapter 3, we’ll see many different hardware implementations of half-hardware implementations of half-adders and full-addersadders and full-adders
Apr 20, 2023
PJF - 29Chapter 1: Digital Computers and Information
Binary Arithmetic Operations:Binary Arithmetic Operations:SubtractionSubtraction
Learn new borrow rulesLearn new borrow rules 0-0 = 1-1 = 0b0 (result 0 with borrow 0)0-0 = 1-1 = 0b0 (result 0 with borrow 0) 1-0 = 1b01-0 = 1b0 0-1 = 1b10-1 = 1b1 …… BorrowBorrow 11 11 00 00
MinuendMinuend 11 11 00 11 11
SubtrahenSubtrahendd
00 11 11 00 11
ResultResult 00 11 11 11 00
Apr 20, 2023
PJF - 30Chapter 1: Digital Computers and Information
Keys to SuccessKeys to Success
Recall and use the “algorithms” you Recall and use the “algorithms” you use to perform base-10 arithmetic.use to perform base-10 arithmetic.
Generalize them to the base in use Generalize them to the base in use (carry, borrow rules change)(carry, borrow rules change)
Preserve the base! In binary, Preserve the base! In binary, 1+1=101+1=10
Two’s complementTwo’s complement Two’s complement of a binary number is Two’s complement of a binary number is
computed as complementing each bit computed as complementing each bit and add 1and add 1 It is used for subtrahend in subtraction It is used for subtrahend in subtraction For example, (3)For example, (3)1010=(011)=(011)22, so (-, so (-
3)3)1010=(100+1)=(100+1)22
(111)-(011)=(111)+(101)=(1100) removing (111)-(011)=(111)+(101)=(1100) removing the leading carry = (100)the leading carry = (100)
Why?Why? x-(011)=x-[111-100]=x-[1000-1-100]=x-x-(011)=x-[111-100]=x-[1000-1-100]=x-
(100+1)-1000(100+1)-1000Apr 20, 2023
PJF - 31Arithmetic
Apr 20, 2023
PJF - 32Chapter 1: Digital Computers and Information
Binary Arithmetic Operations: Binary Arithmetic Operations: MultiplicationMultiplication
Shift-and-add algorithm, as in base 10Shift-and-add algorithm, as in base 10
Check: 13 * 6 = 78Check: 13 * 6 = 78
M’candM’cand 00 00 00 11 11 00 11
M’plierM’plier 00 00 00 00 11 11 00
(1)(1) 00 00 00 00 00 00 00
(2)(2) 00 00 11 11 00 11 00
(3)(3) 00 11 11 00 11 00 00
SumSum 11 00 00 11 11 11 00
Apr 20, 2023
PJF - 33Chapter 1: Digital Computers and Information
CODESCODES
Representations of info (set) obtained by Representations of info (set) obtained by associating one or more associating one or more codewordscodewords (a binary (a binary pattern/string) with each element in the setpattern/string) with each element in the set
n-bitn-bit binary code: a group of binary code: a group of nn bits that can bits that can encode up to encode up to 2 2 n n distinct elementsdistinct elements
e.g. A set of 4 distinct numbers can be e.g. A set of 4 distinct numbers can be represented by 2-bit codes s.t. each number represented by 2-bit codes s.t. each number in the set is assigned exactly one of the in the set is assigned exactly one of the combinations/codes in {00,01,10,11}combinations/codes in {00,01,10,11}
Apr 20, 2023
PJF - 34Chapter 1: Digital Computers and Information
CODES (cont.)CODES (cont.)
To encode To encode mm distinct elements with distinct elements with
an an n-bitn-bit code: code: 22nn >=>= m m Note: The codeword associated with Note: The codeword associated with
each number is obtained by each number is obtained by codingcoding the number, not the number, not convertingconverting the the number to binary.number to binary.
We will see: BCD, ASCII, Unicode We will see: BCD, ASCII, Unicode
Apr 20, 2023
PJF - 35Chapter 1: Digital Computers and Information
Binary-Coded Decimal Binary-Coded Decimal (BCD)(BCD)
A A decimaldecimal code: code: Decimal numbers Decimal numbers (0..9) are coded (0..9) are coded using 4-bit distinct using 4-bit distinct binary wordsbinary words
Observe that the Observe that the codes 1010 .. 1111 codes 1010 .. 1111 (decimal 10..15) are (decimal 10..15) are NOT represented NOT represented (invalid BCD codes)(invalid BCD codes)
Apr 20, 2023
PJF - 36Chapter 1: Digital Computers and Information
Binary-Coded Decimal Binary-Coded Decimal (cont.)(cont.)
To code a number with To code a number with nn decimal digits, decimal digits, we need we need 4n4n bits in BCD bits in BCD
e.g. (365)e.g. (365)1010 = (0011 0110 0101) = (0011 0110 0101)BCDBCD
This is different to converting to binary, This is different to converting to binary, which is (365)which is (365)1010 = (101101101) = (101101101)22
Clearly, BCD requires more bits. BUT, it Clearly, BCD requires more bits. BUT, it is easier to understand/interpretis easier to understand/interpret
Apr 20, 2023
PJF - 37Chapter 1: Digital Computers and Information
BCD AdditionBCD Addition
When 2 BCD codes are added:When 2 BCD codes are added: If the binary sum is less than 1010 (9 in If the binary sum is less than 1010 (9 in
decimal), the corresponding BCD sum decimal), the corresponding BCD sum digit is correctdigit is correct
If the binary sum is equal or more than If the binary sum is equal or more than 1010, must add 0110 (6 in decimal) to 1010, must add 0110 (6 in decimal) to the corresponding BCD sum digit in the corresponding BCD sum digit in order to produce the correct carry into order to produce the correct carry into the digit to the leftthe digit to the left
Apr 20, 2023
PJF - 38Chapter 1: Digital Computers and Information
BCD Addition (cont.)BCD Addition (cont.)
Example: Add 448 and 489 in BCD.Example: Add 448 and 489 in BCD. 0100 0100 1000 0100 0100 1000 (448 in BCD)(448 in BCD)
0100 1000 10010100 1000 1001 (489 in BCD)(489 in BCD)
10001 10001 (greater than 9, add 6)(greater than 9, add 6)
11 0111 0111 (carry 1 into middle digit)(carry 1 into middle digit)
1101 1101 (greater than 9, add 6)(greater than 9, add 6)
1001 1001 11 0011 0011 (carry 1 into leftmost digit)(carry 1 into leftmost digit)
1001 0011 0111 1001 0011 0111 (BCD coding of 937(BCD coding of 9371010) )
Apr 20, 2023
PJF - 39Chapter 1: Digital Computers and Information
ASCII character codeASCII character code We also need to represent letters and We also need to represent letters and
other symbols other symbols alphanumericalphanumeric codes codes ASCII = American Standard Code for ASCII = American Standard Code for
Information Interchange. Also know as Information Interchange. Also know as Western EuropeanWestern European
It contains 128 characters:It contains 128 characters: 94 printable ( 26 upper case and 26 lower case 94 printable ( 26 upper case and 26 lower case
letters, 10 digits, 32 special symbols)letters, 10 digits, 32 special symbols) 34 non-printable (for control functions)34 non-printable (for control functions)
Uses 7-bit binary codes to represent each Uses 7-bit binary codes to represent each of the 128 charactersof the 128 characters
Apr 20, 2023
PJF - 40Chapter 1: Digital Computers and Information
ASCII TableASCII Table
Apr 20, 2023
PJF - 41Chapter 1: Digital Computers and Information
UnicodeUnicode
Established standard (16-bit Established standard (16-bit alphanumeric code) for international alphanumeric code) for international character setscharacter sets
Since is 16-bit, it has 65,536 codesSince is 16-bit, it has 65,536 codes Represented by 4 Hex digitsRepresented by 4 Hex digits ASCII is between 0000ASCII is between 00001616 .. 007B .. 007B1616
Apr 20, 2023
PJF - 42Chapter 1: Digital Computers and Information
Unicode Table (first 191 Unicode Table (first 191 char.)char.)
Apr 20, 2023
PJF - 43Chapter 1: Digital Computers and Information
ASCII Parity BitASCII Parity Bit
Parity coding is used to detect errors Parity coding is used to detect errors in data communication and in data communication and processingprocessing
An 8An 8thth bit is added to the 7-bit ASCII bit is added to the 7-bit ASCII codecode
Even (Odd)Even (Odd) parity: set the parity bit parity: set the parity bit so as to make the # of 1’s in the 8-so as to make the # of 1’s in the 8-bit code even (odd)bit code even (odd)
Apr 20, 2023
PJF - 44Chapter 1: Digital Computers and Information
ASCII Parity Bit (cont.)ASCII Parity Bit (cont.)
For example:For example: Make the 7-bit code 1011011 an 8-bit Make the 7-bit code 1011011 an 8-bit
even parity code even parity code 11011011 11011011 Make the 7-bit code 1011011 an 8-bit Make the 7-bit code 1011011 an 8-bit
odd parity code odd parity code 01011011 01011011 Both even and odd parity codes can Both even and odd parity codes can
detect an odd number of error. An detect an odd number of error. An even number of errors goes even number of errors goes undetected.undetected.
SummarySummary
Conversion between different Conversion between different number systemnumber system
Binary ArithmeticBinary Arithmetic
Apr 20, 2023
PJF - 45Arithmetic