0% found this document useful (0 votes)
65 views76 pages

Digital Logic Design More Number Systems/Complements

Binary numbers are represented using only the digits 0 and 1. Each digit position in a binary number represents a power of 2, from right to left. For example, the binary number 1011 represents 1×23 + 0×22 + 1×21 + 1×20 = 11 in decimal. Binary numbers are important because electrical circuits can easily represent the two values of 0 and 1, making binary well-suited for digital electronics and computing.

Uploaded by

lovely person
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views76 pages

Digital Logic Design More Number Systems/Complements

Binary numbers are represented using only the digits 0 and 1. Each digit position in a binary number represents a power of 2, from right to left. For example, the binary number 1011 represents 1×23 + 0×22 + 1×21 + 1×20 = 11 in decimal. Binary numbers are important because electrical circuits can easily represent the two values of 0 and 1, making binary well-suited for digital electronics and computing.

Uploaded by

lovely person
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 76

Digital Logic Design

Lecture 2

More Number Systems/Complements

1
Understanding Octal Numbers

° Octal numbers are made of octal digits: (0,1,2,3,4,5,6,7)


° How many items does an octal number represent?
• (4536)8 = 4x83 + 5x82 + 3x81 + 6x80 = (1362)10

° What about fractions?


• (465.27)8 = 4x82 + 6x81 + 5x80 + 2x8-1 + 7x8-2

° Octal numbers don’t use digits 8 or 9


° Who would use octal number, anyway?

2
Understanding Binary Numbers

° Binary numbers are made of binary digits (bits):


• 0 and 1

° How many items does an binary number represent?


• (1011)2 = 1x23 + 0x22 + 1x21 + 1x20 = (11)10

° What about fractions?


• (110.10)2 = 1x22 + 1x21 + 0x20 + 1x2-1 + 0x2-2

° Groups of eight bits are called a byte


• (11001001) 2

° Groups of four bits are called a nibble.


• (1101) 2

3
Why Use Binary Numbers?
° Easy to represent 0 and 1 using
electrical values.
° Possible to tolerate noise.
° Easy to transmit data
° Easy to build binary circuits.
AND Gate

1
0
0

4
001 = 1
Binary
010 = 2
011 = 3
In Binary, there are only 0’s and 1’s. These numbers are called “Base-2” ( Example: 0102)

100 = 4 We count in “Base-10”


101 = 5 (0 to 9)
° Binary number has base 2
Decimal

110 = 6
° Each digit is one of two numbers:
111 = 7 0 and 1
Binary to

° Each digit is called a bit


° Eight binary bits make a byte
° All 256 possible values of a byte
can be represented using 2 digits
5
Binary as a Voltage

° Voltages are used to represent logic values:

° A voltage present (called Vcc or Vdd) = 1

° Zero Volts or ground (called gnd or Vss) = 0


A simple switch can provide a logic high or a logic low.

6
A Simple Switch

° Here is a simple switch used to provide a logic value:

Vcc Vcc

Vcc, or 1 Gnd, or 0

There are other ways to connect a switch.

7
Binary digits

Bit: single binary digit

Byte: 8 binary digits

Bit

100101112
Radix

Byte

8
Conversion Between Number Bases

Octal(base 8)

Decimal(base 10) Binary(base 2)

Hexadecimal
° (base16)
Learn to convert between bases.
° Already demonstrated how to convert from
binary to decimal.
° Hexadecimal described in next section

9
Number Systems

Used by Used in
System Base Symbols humans? computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa- 16 0, 1, … 9, No No
decimal A, B, … F

10
Conversion Among Bases

The possibilities:

Decimal Octal

Binary Hexadecimal

11
Convert an Integer from Decimal to Another Base

For each digit position:


1. Divide decimal number by the base (e.g. 2)
2. The remainder is the lowest-order digit
3. Repeat first two steps until no divisor remains.
Example for (13)10:
Integer Remainder Coefficient
Quotient
13/2 = 6 + 1 a0 = 1
6/2 = 3 + 0 a1 = 0
3/2 = 1 + 1 a2 = 1
1/2 = 0 + a3 = 1

Answer (13)10 = (a3 a2 a1 a0)2 = (1101)2

12
Convert an Fraction from Decimal to Another Base

For each digit position:


1. Multiply decimal number by the base (e.g. 2)
2. The integer is the highest-order digit
3. Repeat first two steps until fraction becomes zero.
Example for (0.625)10:
Integer Fraction Coefficient
0.625 x 2 = 1 + 0.25 a -1 = 1
0.250 x 2 = 0 + 0.50 a -2 = 0
0.500 x 2 = 1 + 0 a -3 = 1

Answer (0.625)10 = (0.a-1 a-2 a-3 )2 = (0.101)2

13
The Growth of Binary Numbers
n 2n n 2n
0 20=1 8 28=256
1 21=2 9 29=512

2 22=4 10 210=1024

3 23=8 11 211=2048

4 24=16 12 212=4096

5 25=32 20 220=1M Mega

Giga
6 26=64 30 230=1G

Tera
7 2 =128
7
40 2 =1T
40

14
Binary Addition

° Binary addition is very simple.


° This is best shown in an example of adding two binary
numbers…

1 1 1 1 1 1 carries
1 1 1 1 0 1
+ 1 0 1 1 1
---------------------
1 0 1 0 1 0 0

15
Binary Subtraction

° We can also perform subtraction (with borrows in place of carries).


° Let’s subtract (10111)2 from (1001101)2…

1 10 borrows
0 10 10 0 0 10

1 0
0 1 1 0 1
- 1 0 1 1 1
------------------------
1 1 0 1 1 0

16
Binary Multiplication

° Binary multiplication is much the same as decimal


multiplication, except that the multiplication operations
are much simpler…

1 0 1
1 1
X 1 0 1 0
-----------------------
0 0 0 0 0
1 0 1 1 1
0 0 0 0 0
1 0 1 1 1
-----------------------
1 1 1 0 0 1 1 0
17
Convert an Integer from Decimal to Octal

For each digit position:


1. Divide decimal number by the base (8)
2. The remainder is the lowest-order digit
3. Repeat first two steps until no divisor remains.
Example for (175)10:
Integer Remainder Coefficient
Quotient
175/8 = 21 + 7/8 a0 = 7
21/8 = 2 + 5/8 a1 = 5
2/8 = 0 + 2/8 a2 = 2

Answer (175)10 = (a2 a1 a0)2 = (257)8

18
Convert an Fraction from Decimal to Octal

For each digit position:


1. Multiply decimal number by the base (e.g. 8)
2. The integer is the highest-order digit
3. Repeat first two steps until fraction becomes zero.
Example for (0.3125)10:
Integer Fraction Coefficient
0.3125 x 8 = 2 + 5 a -1 = 2
0.5000 x 8 = 4 + 0 a -2 = 4

Answer (0.3125)10 = (0.24)8

19
Overview

° Hexadecimal numbers
• Related to binary and octal numbers

° Conversion between hexadecimal, octal and binary


° Value ranges of numbers
° Representing positive and negative numbers
° Creating the complement of a number
• Make a positive number negative (and vice versa)

° Why binary?

20
Understanding Binary Numbers

° Binary numbers are made of binary digits (bits):


• 0 and 1

° How many items does an binary number represent?


• (1011)2 = 1x23 + 0x22 + 1x21 + 1x20 = (11)10

° What about fractions?


• (110.10)2 = 1x22 + 1x21 + 0x20 + 1x2-1 + 0x2-2

° Groups of eight bits are called a byte


• (11001001) 2

° Groups of four bits are called a nibble.


• (1101) 2
21
Understanding Hexadecimal Numbers

° Hexadecimal numbers are made of 16 digits:


• (0,1,2,3,4,5,6,7,8,9,A, B, C, D, E, F)

° How many items does an hex number represent?


• (3A9F)16 = 3x163 + 10x162 + 9x161 + 15x160 = 1499910

° What about fractions?


• (2D3.5)16 = 2x162 + 13x161 + 3x160 + 5x16-1 = 723.312510

° Note that each hexadecimal digit can be represented with four


bits.
• (1110) 2 = (E)16

° Groups of four bits are called a nibble.


• (1110) 2 22
Putting It All Together

° Binary, octal, and


hexadecimal similar
° Easy to build circuits to
operate on these
representations
° Possible to convert
between the three formats

23
Converting Between Base 16 and Base 2

3A9F16 = 0011 1010 1001 11112


3 A 9 F

° Conversion is easy!
 Determine 4-bit value for each hex digit
° Note that there are 24 = 16 different values of four bits
° Easier to read and write in hexadecimal.
° Representations are equivalent!

24
Converting Between Base 16 and Base 8

3A9F16 = 0011 1010 1001 11112


3 A 9 F

352378 = 011 101 010 011 1112


3 5 2 3 7

1. Convert from Base 16 to Base 2


2. Regroup bits into groups of three starting from right
3. Ignore leading zeros
4. Each group of three bits forms an octal digit.
25
Number systems (Octal
( Numbers)
Octal Numbers:
[Base 8],[ 0,1,3,4,5,6,7]

Octal to Decimal Conversion:


Example:-
°Octal number has base 8
[2374]8 = [ ? ]10 °Each digit is a number from 0 to 7

=4×8 +7×8 +3×8 +2×8


0 1 2 3 °Each digit represents 3 binary bits
°Was used in early computing, but was replaced by hexadecimal

=[1276]10

26
Number systems (Octal
( Numbers)

Decimal to Octal Conversion:


The Division: 359 Quotient Reminder
 44 7
8
[359]10 = [ ? ]8 44
5 4
By using the division system:
8
5 5
0
8

5 4 7
27
Number systems (Octal
( Numbers)

Binary to Octal Conversion:


Example:-
[110101]2 = [ ? ]8
Here we will take 3 bits and convert it from binary to decimal
by using the decimal to binary truth table:

Binary Decimal
110 6

101 5
110 101 = (65)8

{
{
6 5

28
Number systems (Octal
( Numbers)

Octal to Binary Conversion:


Example:-
[13]8 = [ ? ]2
Here we will convert each decimal digit from decimal to binary
(3 bits) using the decimal to binary truth table:

Binary Decimal
1 001

3 011
(13)8 = (001011)2

29
Radix Based Conversion (Example)

° Convert 1234 decimal into octal

Radix 8 Answer
8 1234 
8 154 2
Divide
8 19 2 23228
by radix 8
  2 3

30
Octals

• Converting to decimal from octal:


– Evaluate the power series
• Example

2 1 0
2 0 78

2*8 2 + 0*81 + 7*80

= 13510
31
Hexadecimal
° Hexadecimal is used to simplify dealing with large binary values:
• Base-16, or Hexadecimal, has 16 characters: 0-9, A-F
• Represent a 4-bit binary value: 00002 (0) to 11112 (F)
• Easier than using ones and zeros for large binary values
• Commonly used in computer applications

° Examples:
• 11002 = 1210 = C16
• 1010 0110 1100 00102 = A6 C216
Hex values can be followed by an “H” to indicate base-16. Example: A6 C2 H

32
Hex Values in Computers

33
Decimal to Hexadecimal
Decimal Hex
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 A
11 B
12 C
13 D
14 E
15 F
34
Conversion Binary to Hexadecimal

1 0 1 0 1 1 0 0 0 0 0 1 0 1 1 0

1010 = 10 1100 = 12 0001 = 1 0110 = 6

A C 1 6

35
Radix Based Conversion (Example)

° Convert 1234 decimal into hexadecimal

Radix 16 Answer
16 1234 
Divide
16 77 2
4D216
by radix 16   4 D

36
Hexadecimals – Base 16

• Converting to decimal from hex:


– Evaluate the power series
• Example

2 1 0
2 E A 16

2*16 2 + 14*161 + 10*160

= 74610
37
Octal to Hex Conversion

 To convert between the Octal and Hexadecimal numbering


systems
 Convert from one system to binary first
 Then convert from binary to the new numbering system

38
Hex to Octal Conversion
Ex : Convert E8A16 to octal
First convert the hex to binary:
1110 1000 10102

111 010 001 010 and re-group by 3 bits


(starting on the right)
Then convert the binary to octal:
7 2 1 2

39
Octal to Hex Conversion
Ex : Convert 7528 to hex
First convert the octal to binary:
111 101 010re-group
2 by 4 bits

0001 1110 1010 (add leading zeros)


Then convert the binary to hex:
1 E A

So 7528 = 1EA16
40
Octal to Hexadecimal

Decimal Octal

Binary Hexadecimal

41
Octal to Hexadecimal

° Technique
• Use binary as an intermediary

42
Example

10768 = ?16
1 0 7 6

001 000 111 110

2 3 E

10768 = 23E16

43
Hexadecimal to Octal

Decimal Octal

Binary Hexadecimal

44
Hexadecimal to Octal

° Technique
• Use binary as an intermediary

45
Example

1F0C16 = ?8
1 F 0 C

0001 1111 0000 1100

1 7 4 1 4

1F0C16 = 174148

46
Example: Hex → Octal
Example:

° Convert the hexadecimal number 5AH into its octal


equivalent.
Solution:

° First convert the hexadecimal number into its decimal


equivalent, then convert the decimal number into its octal
equivalent.
5 A 8 90
11
r  2  LSB
161 160
1
16 1
8 11 r 3

0
80 + 10 = 9010 8 1 r  1  MSB

5AH = 1328
47
Fractions (Example)

48
Fractions (Example)

49
Radix Based Conversion (Example)

° Convert 0.6875 decimal into binary

Radix 2
Multiply by radix 2

Fraction Radix Total (Fraction x Radix) Integer Fraction


0.6875 2 1.375 1 0.375
0.375 2 0.75 0 0.75
0.75 2 1.5 1 0.5
0.5 2 1 1 0
Answer 0.10112

50
Radix Based Conversion (Example)

° Convert 0.51310 to base 16 (up to 4 fractional point)

Radix 16 Multiply by radix 16

Fraction Radix Total (Fraction x Radix) Integer Fraction


0.513 16 8.208 8 0.208
0.208 16 3.328 3 0.328
0.328 16 5.248 5 0.248
0.248 16 3.968 3 0.968

Answer 0.835316

51
°Lecture 03

°2’s Complement

52
How To Represent Signed Numbers
• Plus and minus sign used for decimal numbers: 25
(or +25), -16, etc.
• For computers, desirable to represent everything as
bits.
• Three types of signed binary number representations:
signed magnitude, 1’s complement, 2’s complement.
• In each case: left-most bit indicates sign: positive (0)
or negative (1).
Consider signed magnitude:
000011002 = 1210 100011002 = -1210

Sign bit Magnitude Sign bit Magnitude

53
Complement
° It has already been studied that
° subtracting one number from another is the same as making one
number negative and just adding them.
° We know how to create negative numbers in the binary number
system.
° How to perform 2’s complement process.
° How the 2’s complement process can be use to add (and subtract)
binary numbers.
° Digital electronics requires frequent addition and subtraction of
numbers. You know how to design an adder, but what about a
subtracter?
° A subtracter is not needed with the 2’s complement process. The 2’s
complement process allows you to easily convert a positive number54
3-Digit Decimal
A bicycle odometer with only three
digits is an example of a fixed-
999
length decimal number system. forward (+)
998

The problem is that without a 997

negative sign, you cannot tell a +998


001
from a -2 (also a 998). Did you ride
000
forward for 998 miles or backward
999
for 2 miles?
998

Note: Car odometers do not work this


002
way. 001
backward (-)

55
Negative Decimal
+499 499
How do we represent negative pos(+)
+498 498
numbers in this 3-digit decimal
+497 497
number system without using a
sign?
+001 001

Cut the number system in half. 000 000

Use 001 – 499 to indicate positive -001 999

numbers. -002 998

Use 500 – 999 to indicate negative -499 501


numbers. -500 500
neg(-)

Notice that 000 is not positive or


negative.
56
3-Digit Decimal (Examples)

3 003 6 006
+ 2 + 002 + (-3) + 997
5 005 3 1003
Disregard
Overflow

(-5) 995 (-2) 998


+ 2 + 002 + (-3) + 997
(-3) 997 (-5) 1995
Disregard
Overflow

It Works!
57
Complex Problem

° The previous examples demonstrate that this


process works, but how do we easily convert a
number into its negative equivalent?
° In the examples, converting the negative numbers
into the 3-digit decimal number system was fairly
easy. To convert the (-3), you simply counted
backward from 1000 (i.e., 999, 998, 997).
° This process is not as easy for large numbers (e.g.,
-214 is 786). How did we determine this?
° To convert a large negative number, you can use the
10’s Complement Process.

58
Complement

The 10’s Complement process uses base-10 (decimal)


numbers. Later, when we’re working with base-2
(binary) numbers, you will see that the 2’s
Complement process works in the same way.
First, complement all of the digits in a number.
• A digit’s complement is the number you add to the digit to
make it equal to the largest digit in the base (i.e., 9 for
decimal). The complement of 0 is 9, 1 is 8, 2 is 7, etc.
Second, add 1.
• Without this step, our number system would have two
zeroes (+0 & -0), which no number system has.

59
10’s Complement Examples

Example #1
-003 Complement Digits

996
+1 Add 1
997
Example #2
-214
Complement Digits

785
+1 Add 1
60
One’s Complement Representation
• The one’s complement of a binary number involves
inverting all bits.
• 1’s comp of 00110011 is 11001100
• 1’s comp of 10101010 is 01010101
• For an n bit number N the 1’s complement is (2n-1) –
N.
• Called diminished radix complement by Mano since
1’s complement for base (radix 2).
• To 00001100
find negative
= 12 of 1’s complement number take the
11110011 = -12
1’s complement.
2 10 2 10

Sign bit Magnitude Sign bit Magnitude

61
Two’s Complement Representation
• The two’s complement of a binary number involves
inverting all bits and adding 1.
• 2’s comp of 00110011 is 11001101
• 2’s comp of 10101010 is 01010110
• For an n bit number N the 2’s complement is (2n-1) – N
+ 1.
• Called radix complement by Mano since 2’s
complement for base (radix 2).
• To 00001100
find negative
= 12 of 2’s complement number take the
11110100 = -12
2’s complement.
2 10 2 10

Sign bit Magnitude Sign bit Magnitude

62
Two’s Complement Shortcuts
° Algorithm 1 – Simply complement each bit and then add 1
to the result.
• Finding the 2’s complement of (01100101)2 and of its 2’s complement…
N = 01100101 [N] = 10011011
10011010 01100100
+ 1 + 1
--------------- ---------------
10011011 01100101

° Algorithm 2 – Starting with the least significant bit, copy


all of the bits up to and including the first 1 bit and then
complementing the remaining bits.
• N =01100101
[N] = 1 0 0 1 1 0 1 1
63
Finite Number Representation

° Machines that use 2’s complement arithmetic can


represent integers in the range
-2n-1 <= N <= 2n-1-1
where n is the number of bits available for representing N.
Note that 2n-1-1 = (011..11)2 and –2n-1 = (100..00)2
o For 2’s complement more negative numbers than positive.
o For 1’s complement two representations for zero.
o For an n bit number in base (radix) z there are zn different
unsigned values.
(0, 1, …zn-1)
64
1’s Complement Addition
° Using 1’s complement numbers, adding numbers is easy.
° For example, suppose we wish to add +(1100)2 and
+(0001)2.
° Let’s compute (12)10 + (1)10.
• (12)10 = +(1100)2 = 011002 in 1’s comp.
• (1)10 = +(0001)2 = 000012 in 1’s comp. 0 1 1 0 0
Add
+ 0 0 0 0 1
Step 1: Add binary numbers
Step 2: Add carry to low-order bit --------------
Add carry 0 0 1 1 0 1
0
Final
Result --------------
0 1 1 0 1
65
1’s Complement Subtraction
° Using 1’s complement numbers, subtracting numbers is
also easy.
° For example, suppose we wish to subtract +(0001)2 from
+(1100)2. 0 1 1 0 0
° Let’s compute (12)10 - (1)10. - 0 0 0 0 1
• (12) = +(1100) = 01100 in 1’s comp.
--------------
10 2 2 1’s comp

• (-1)10 = -(0001)2 = 111102 in 1’s comp.


Step 1: Take 1’s complement of 2nd operand
Step 2: Add binary numbers
Add 0 1 1 0 0
Step 3: Add carry to low order bit
+ 1 1 1 1 0
Add carry
--------------
1 0 1 0 1 0
Final
Result 1
--------------
66
2’s Complement Addition
° Using 2’s complement numbers, adding numbers is easy.
° For example, suppose we wish to add +(1100)2 and
+(0001)2.
° Let’s compute (12)10 + (1)10.
• (12)10 = +(1100)2 = 011002 in 2’s comp.
• (1)10 = +(0001)2 = 000012 in 2’s comp. 0 1 1 0 0
Add
Step 1: Add binary numbers
+ 0 0 0 0 1
Step 2: Ignore carry bit Final --------------
Result
0 0 1 1 0 1

Ignore

67
2’s Complement Subtraction
° Using 2’s complement numbers, follow steps for
subtraction
° For example, suppose we wish to subtract +(0001)2 from
+(1100)2. 0 1 1 0 0
° Let’s compute (12)10 - (1)10. - 0 0 0 0 1
• (12) = +(1100) = 01100 in 2’s comp.
--------------
10 2 2 2’s comp

• (-1)10 = -(0001)2 = 111112 in 2’s comp.


Step 1: Take 2’s complement of 2nd operand
Step 2: Add binary numbers
Add 0 1 1 0 0
Step 3: Ignore carry bit
Final + 1 1 1 1 1
Result
--------------
1 0 1 0 1 1
Ignore
Carry

68
2’s Complement Subtraction: Example #2

° Let’s compute (13)10 – (5)10.


• (13)10 = +(1101)2 = (01101)2
• (-5)10 = -(0101)2 = (11011)2

° Adding these two 5-bit codes…


0 1 1 0 1
carry + 1 1 0 1 1
--------------
10 1 0 0 0

° Discarding the carry bit, the sign bit is seen to be zero,


indicating a correct result. Indeed,
(01000)2 = +(1000)2 = +(8)10. 69
2’s Complement Subtraction: Example #3
° Let’s compute (5)10 – (12)10.
• (-12)10 = -(1100)2 = (10100)2
• (5)10 = +(0101)2 = (00101)2

° Adding these two 5-bit codes…


0 0 1 0 1
+ 1 0 1 0 0
--------------
1 1 0 0 1

° Here, there is no carry bit and the sign bit is 1. This


indicates a negative result, which is what we expect.
(11001)2 = -(7)10.
70
1’s Complement

71
2’s Complement

• 1s complement with negative numbers shifted one position


clockwise
• Only one representation for 0
• One more negative number than positive number
• High-order bit can act as sign bit

72
Overflow
° Overflow conditions
° Add two positive numbers to get a negative number
° Add two negative numbers to get a positive number

73
Two’s Complement Number System

 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 
0
- 1 1
0000
1111 0001 2
- 2
1110 0010

- 3 3
1101 0011

- 4 4
1100 0100

5
1011 0101
- 5

1010 0110
- 6 6
1001 1000 0111
- 7 - 7
8 74
Summary

° Binary numbers are made of binary digits (bits)


° Binary and octal number systems
° Conversion between number systems
° Addition, subtraction, and multiplication in binary

75
Summary

° Binary numbers can also be represented in octal and


hexadecimal
° Easy to convert between binary, octal, and hexadecimal
° Signed numbers represented in signed magnitude, 1’s
complement, and 2’s complement
° 2’s complement most important (only 1 representation for zero).
° Important to understand treatment of sign bit for 1’s and 2’s
complement.

76

You might also like