You are on page 1of 53

Digital Systems Design

01 - Number Systems and Codes


Number Systems

DATE : 04/10/2022 2
Decimal Number System
5 7 4 . 2 4
• Base (radix) = 10
• 10 digits
• {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} 102 101 100 10−1 10−2
• Digit Position
100 10 1 0.1 0.01
• Integer & fraction
• Digit Weight
• 𝑤𝑒𝑖𝑔ℎ𝑡 = (𝐵𝑎𝑠𝑒)𝑃𝑜𝑠𝑖𝑡𝑖𝑜𝑛 5*100 7*10 4*1 2*0.1 4*0.01
• Magnitude
500 + 70 + 4 + 0.2 + 0.04
• Sum of “Digit x Weight”
• Formal Notation 𝑎2 ∗ 𝐵2 + 𝑎1 ∗ 𝐵1 + 𝑎0 ∗ 𝐵0 + 𝑎−1 ∗ 𝐵−1 + 𝑎−2 ∗ 𝐵−2

574.24 10
Octal Number System
5 7 4 . 2 4
• Base (radix) = 8
• 8 digits
• {0, 1, 2, 3, 4, 5, 6, 7} 82 81 80 8−1 8−2
• Digit Position
64 8 1 1/8 1/64
• Integer & fraction
• Digit Weight
• 𝑤𝑒𝑖𝑔ℎ𝑡 = (𝐵𝑎𝑠𝑒)𝑃𝑜𝑠𝑖𝑡𝑖𝑜𝑛 5*64 7*8 4*1 2*1/8 4*1/64
• Magnitude
320 + 56 + 4 + 0.25 + 0.0625
• Sum of “Digit x Weight”
• Formal Notation 𝑎2 ∗ 𝐵2 + 𝑎1 ∗ 𝐵1 + 𝑎0 ∗ 𝐵0 + 𝑎−1 ∗ 𝐵−1 + 𝑎−2 ∗ 𝐵−2

380.3125 10 574.24 8 4
Hexadecimal Number System
• Base (radix) = 16 1 E 5 . 7 A
• 16 digits
• {0, 1, 2, 3, 4, 5, 6, 7, 8, 162 161 160 16−1 16−2
• 9, A, B, C, D, E, F}
• Digit Position 256 16 1 1/16 1/256
• Integer & fraction
• Digit Weight
1*256 14*16 5*1 7*1/16 10*1/256
• 𝑤𝑒𝑖𝑔ℎ𝑡 = (𝐵𝑎𝑠𝑒)𝑃𝑜𝑠𝑖𝑡𝑖𝑜𝑛
• Magnitude
256 + 224 + 5 + 0.4375 + 0.0390
• Sum of “Digit x Weight” 625
• Formal Notation 𝑎2 ∗ 𝐵2 + 𝑎1 ∗ 𝐵1 + 𝑎0 ∗ 𝐵0 + 𝑎−1 ∗ 𝐵−1 + 𝑎−2 ∗ 𝐵−2

485.4765625 10 1𝐸5.7𝐴 16 5
Binary Number System
1 0 1 . 0 1
• Base (radix) = 2
• 2 digits {0, 1}
• binary digits “bits” 22 21 20 2−1 2−2
• Digit Position
4 2 1 1/2 1/4
• Integer & fraction
• Digit Weight
• 𝑤𝑒𝑖𝑔ℎ𝑡 = (𝐵𝑎𝑠𝑒)𝑃𝑜𝑠𝑖𝑡𝑖𝑜𝑛 1*4 0*2 1*1 0*1/2 1*1/4
• Magnitude
4 + 0 + 1 + 0 + 0.25
• Sum of “Digit x Weight”
• Formal Notation 𝑎2 ∗ 𝐵2 + 𝑎1 ∗ 𝐵1 + 𝑎0 ∗ 𝐵0 + 𝑎−1 ∗ 𝐵−1 + 𝑎−2 ∗ 𝐵−2

5.25 10 101.01 2 6
Binary Number System

7
Number Base Conversion

8
Decimal to Binary/Octal/Hexadecimal
• Integer Conversion
1. Divide the number by the “Base”
2. Take the remainder as a coefficient
3. Take the quotient and repeat the division

• Fraction conversion
1. Multiply the number by the “Base”
2. Take the integer part as a coefficient
3. Take the resultant fraction repeat the multiplication

9
Decimal to Binary/Octal/Hexadecimal
• Example: 13 10 to binary
More conveniently

Quotient Remainder Coefficient Integer Remainder


13/2 6 1 𝑎0 = 1 13
6/2 3 0 𝑎1 = 0 6 1
3/2 1 1 𝑎2 = 1 3 0
1 0 1 𝑎3 = 1 1 1
0 1

• Answer: 13 10 = 𝑎3 𝑎2 𝑎1 𝑎0 = 1101 2

MSB LSB 10
Decimal to Binary/Octal/Hexadecimal
• Example: 41 10 to binary Integer Remainder
Quotient Remainder Coefficient 41
41/2 20 1 𝑎0 = 1 20 1
20/2 10 0 𝑎1 = 0 10 0
10/2 5 0 𝑎2 = 0 5 0
5/2 2 1 𝑎3 = 1 2 1
2/2 1 0 𝑎4 = 0 1 0
1/2 0 1 𝑎5 = 1 0 1

• Answer: 41 10 = 𝑎5 𝑎4 𝑎3 𝑎2 𝑎1 𝑎0 = 101001 2

11
Decimal to Binary/Octal/Hexadecimal
• Example: 153 10 to octal

Integer Remainder
153
19 1
2 3
0 2

• Answer: 153 10 = 𝑎2 𝑎1 𝑎0 = 231 8

12
Decimal to Binary/Octal/Hexadecimal
• Example: 0.6875 10 to binary
Integer Fraction Coefficient
0.6875*2 1 0.3750 𝑎−1 = 1
0.3750*2 0 0.7500 𝑎−2 = 0
0.7500*2 1 0.500 𝑎−3 = 1
0.500*2 1 0.000 𝑎−4 = 1

• Answer: 0.6875 10 = 0. 𝑎−1 𝑎−2 𝑎−3 𝑎−4 = 0.1011 2

13
Decimal to Binary/Octal/Hexadecimal
• Example: 0.513 10 to octal

0.513*8 4.104
0.104*8 0.832
0.832*8 6.656
0.656*8 5.248
0.248*8 1.984
0.984*8 7.872

• Answer: 0.513 10 = 0.406517 … 8 to seven significant figures

14
Decimal to Binary/Octal/Hexadecimal
• Using the examples above

• 41.6875 10 = 101001.1011 2

• 153.513 10 = 231.406517 8

15
Decimal to Binary/Octal/Hexadecimal
• Example: 834.75 10 to hexadecimal
Integer Remainder
834
52 2 0.75*16 12.00
3 4
0 3

• Answer: 834.75 10 = 342. 𝐶 16

16
Octal and Hexadecimal Numbers
• Shorter patterns hex characters are easier to recognize than longer
patterns of 1’s and 0’s
• Each octal digit corresponds to three binary digits (since 23 = 8)
• Each hexadecimal digit corresponds to four binary digits (since 24 =
16)

17
Binary to octal conversion
• Example: 10110.01 2 to octal

• Works both ways (binary to octal and octal to binary)

18
Binary to hexadecimal Conversion
• Example: 10110.01 2 to hexadecimal

• Works both ways (binary to hex and hex to binary)

19
Octal to hexadecimal conversion
• Convert to binary as an intermediate step

20
Octal to hexadecimal conversion
• Examples:

21
Binary Arithmetic

22
Addition
• Decimal Addition

23
Addition
• Arithmetic operations in digital systems are usually done in binary
• Design of logic circuits for binary arithmetic is much easier than for
decimal

• The addition table for binary numbers is


• 0+0=0
• 0+1=1
• 1+0=1
• 1+1=0 and carry 1 to the next column

24
Addition
• Binary Addition

25
Addition
• Example: 1101 + 1011
• Answer: 11000

• Example: 101101 + 100111


• Answer: 1010100

26
Subtraction
• The subtraction table for binary numbers is
• 0−0=0
• 0−1=1 and borrow 1 from the next column
• 1−0=1
• 1−1=0

• Borrowing 1 from a column is equivalent to subtracting 1 from that


column

27
Subtraction

28
Subtraction
• Example: 11101 – 10011
• Answer: 1010

• Example: 111001 – 1011


• Answer: 101110

• Example: 10000 – 11
• Answer: 1101

29
Multiplication
• The multiplication table for binary numbers is
• 0∗0=0
• 0∗1=0
• 1∗0=0
• 1∗1=1

• Multiplication is done bit by bit

30
Multiplication
= 23 10

= 10 10

= 230 10

31
Multiplication
• Example: 1011 * 101
• Answer: 110111

• Example: 1101 * 1011


• Answer: 10001111

32
Representation of Negative Numbers

33
Representation of Negative Numbers
• To represent negative integers, a notation for the negative values is
needed
• It is customary to represent the sign with a bit placed in the leftmost
position of the binary number
• The convention is to make the sign bit 0 for positive and 1 for
negative
• The most common methods for representing both positive and
negative numbers are:
• Signed-magnitude
• 2’s complement
• 1’s complement

34
Signed-Magnitude Numbers
• Consider an n-bit sign and magnitude number
bit 0
0 +ve bit 1 bit 2 … bit n-2 bit n-1
1 -ve

• 1 bit for the sign and n-1 bits for the magnitude
• Number in the range − 2𝑛−1 − 1 to + 2𝑛−1 − 1 are represented
• Including +0 and -0

• Designing logic circuits to perform arithmetic on sign and magnitude is not


easy

35
Signed-Magnitude Numbers
• 𝑛=4
• Can represent numbers between -7 and +7
+𝑁 Positive Integers −𝑁 Sign and
Magnitude
+0 0000 -0 1000
+1 0001 -1 1001
+2 0010 -2 1010
+3 0011 -3 1011
+4 0100 -4 1100
+5 0101 -5 1101
+6 0110 -6 1110
+7 0111 -7 1111
36
2’s Complement Numbers
• Consider n-bits numbers
• A positive number 𝐵 is represented by a 0 followed by the magnitude of 𝐵
• A negative number – 𝐵 is represented by its 2’s complement 𝐵∗ , where

𝐵 ∗ = 2𝑛 − 𝐵

• The magnitude of a negative number can be obtained by taking it’s 2’s


complement

𝐵 = 2𝑛 − 𝐵 ∗

• The range of representable numbers is − 2𝑛−1 to + 2𝑛−1 − 1


37
2’s Complement Numbers
• Examples:
2’s Complement Numbers
• Examples:
2’s Complement Numbers
• 𝑛=4
• Can represent the numbers between -8 and +7
+𝑁 Positive Integers −𝑁 2’s Complement
+0 0000 -0 ____
+1 0001 -1 1111
+2 0010 -2 1110
+3 0011 -3 1101
+4 0100 -4 1100
+5 0101 -5 1011
+6 0110 -6 1010
+7 0111 -7 1001
-8 1000
40
Addition of 2’s Complement Numbers
• Addition is carried out as if all the numbers were positive, and any
carry form the sign position is ignored
• This will always yield the correct result except when an overflow
occurs
• An overflow occurs when the correct representation of the sum
(including the sign) requires more than 𝑛 bits

• Assume 𝑛 = 4, the different cases will be illustrated in the next


pages

41
Addition of 2’s Complement Numbers
1. Addition of two positive numbers, sum < 2𝑛−1

2. Addition of two positive numbers, sum≥ 2𝑛−1

42
Addition of 2’s Complement Numbers
3. Addition of positive and negative numbers (negative number has a
greater magnitude)

4. Addition of positive and negative numbers (positive number has a


greater magnitude)

43
Addition of 2’s Complement Numbers
5. Addition of two negative number, |sum|≤ 2𝑛−1

6. Addition of two negative numbers, |sum|> 2𝑛−1

44
Binary Codes for Decimal Numbers

45
Binary Codes for Decimal Numbers
• Digital systems use signals that have two distinct values and circuit
elements that have two stable states
• There is a direct analogy between binary signals, binary circuit
elements, and binary digits
• However, the input and output equipment generally use decimal
numbers
• Therefore, decimal numbers must be coded in terms of binary signals

46
Binary-Coded Decimal (BCD) Code
• Each decimal digit is replaced by its binary equivalent

• A number with 𝑘 decimal digits will require 4𝑘 bits in BCD.


• A decimal number in BCD is the same as its equivalent binary number only
when the number is between 0 and 9
• The binary combinations 1010 through 1111 are not used and have no
meaning in BCD

47
Binary-Coded Decimal (BCD) Code
• A decimal number in BCD is
the same as its equivalent
binary number only when
the number is between 0
and 9
• The binary combinations
1010 through 1111 are not
used and have no meaning
in BCD

48
Other Decimal Codes

49
Gray Code
• Used in applications in which the
normal sequence of binary numbers
generated by hardware may produce
errors or ambiguity during the
transition from one number to the
next
• In Gray code, only one bit changes its
value during any transition between
two numbers

50
Gray Code
ASCII Code
• American Standard Code for Information Interchange (ASCII) Character
Code
• A popular code used to represent information sent as character-based
data.
• It uses 7-bits to represent:
• 94 Graphic printing characters.
• 34 Non-printing characters.
• Some non-printing characters are used for text format (e.g. BS =
Backspace, CR = carriage return).
• Other non-printing characters are used for record marking and flow
control (e.g. STX and ETX start and end text areas).

52
ASCII Code

53

You might also like