0% found this document useful (0 votes)
15 views28 pages

CENG250 Chapter 1 Part 2

Chapter 1 of CENG250 covers the fundamentals of digital logic design, including number representation in binary and hexadecimal, conversion methods, and binary arithmetic operations like addition and subtraction. It explains signed and unsigned numbers, their ranges, and the concept of overflow in arithmetic operations. The chapter concludes with exercises and a reminder for students to ask questions on Google Classroom.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views28 pages

CENG250 Chapter 1 Part 2

Chapter 1 of CENG250 covers the fundamentals of digital logic design, including number representation in binary and hexadecimal, conversion methods, and binary arithmetic operations like addition and subtraction. It explains signed and unsigned numbers, their ranges, and the concept of overflow in arithmetic operations. The chapter concludes with exercises and a reminder for students to ask questions on Google Classroom.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CENG250: Digital Logic 1

Chapter 1 – Introduction to Logic Design


Part 2

1
Outline
• Syllabus and Semester Rules
• Representation of numbers in Binary (Base 2: 0 & 1), Hexadecimal (Base 16)
• Conversion between Binary, Decimal and Hexadecimal
• Addition in Binary
• 2’s complement & Subtraction in Binary
• Signed and unsigned numbers and their range
• Overflow

2
Binary Addition

Example1: 11
0110 6
0111 +7
--------- ------
11 0 1 13

1 +1 +1 = 11 (3, or sum of 1 and a 1x1+0x2+1x4+1x8 = 1+4+8 = 13


carry of 1 to the next bit)
Remember the weights are 8-4-2-1

3
Binary Addition

Example1: 11
0110 6
0111 +7
--------- ------
1101 13

1 +1 +1 = 11 1x1+0x2+1x4+1x8 = 1+4+8 = 13

Carry out = cn = 1

1 101 111111
Example 2: 1101 13 Example 3: 110101
0101 + 5 111111
--------- -------- -------------------
0010 18 110100

4
Unsigned and Signed numbers
• When representing numbers in binary, we might consider them as signed or
unsigned numbers
• Unsigned numbers are numbers that are always positive
• If he have a register of size n bits, then we can put unsigned numbers in the
following range: 0 2n-1
• Signed numbers are numbers that can be positive or negative
• If he have a register of size n bits, then we can put signed numbers in the
following range: -2n-1 2n-1 - 1
• Example: if n = 8 then
• If we are dealing with unsigned numbers, the range will be 0 255
• If we are dealing with signed numbers, the range will be -128 127
• It is the user or designer of the logic circuit is the one who decides whether
he is using the register for unsigned or signed numbers
• In this course, I tell you which one we are dealing with 5
• 4-bit signed Register -2n-1 2n-1 - 1
-23 23 -1 or -8 to 7

How many numbers from -8 to 7


7 – (-8) + 1 = 7 + 8 + 1 = 16

6
Signed numbers? Positive or Negative? How can we tell?

• MSb: Most Significant bit is the first bit to the left in a binary number
• LSb: Least Significant bit is the first bit to the right in a binary number
• Example1: in the binary number 0111000, the MSb is the one colored in red and the
LSb is the one colored in green
• NOTE: the number of bits is determined by the size of the register
• In signed numbers, the MSb indicates if the number is positive or negative
• MSb = 0 the number is positive
• MSb = 1 the number is negative
• Examples:
• (01101111)2signed is a positive number because MSb is 0
• (11001101)2signed is a negative number because MSb is 1
• (11000011)2unsigned is _positive________________
• (01101100)2unsigned is _positive________________
7
MSB and LSB
• Consider an 8-bit register

MSB: Most significant bit


LSB: Least significant bit
• Unsigned numbers =>
Weight = 20 =1
Weight = 2n-1 = 27 =128

• If signed numbers
=>Weight = -2n-1 = -27
=-128 =>
• MSB = 0 (+ve)
• MSB = 1 (-ve) 8
Value of signed binary numbers

9
Unsigned

8421 -8 4 2 1

10
Exercises

• Stored in a 6 bit register, find the decimal representation of the following


numbers:
(001011)2unsigned =8+2+1= 1110

(101011)2unsigned =32+8+2+1 =4310

(001011)2signed = 8+2+1 = +1110

(101011)2signed =-32+8+2+1=-2110

(111111)2signed =-32+16+8+4+2+1=-1
11
Two’s complement

12
Two’s complement
Write -5 in binary (consider a 6 bit signed register)
Ones complement of (0 0 0 1 0 1) =
111010
procedure:
step 1: convert 5 to binary 000101 111010
+ 1
step 2: flip the bits 111010 --------------
step 3: add 1 111011 111011
Verification:
111011 = (-1)*1*25 + 1*24 + 1*23 + 0*22 + 1*21 + 1
= -32 + 16 + 8 + 0 +2 +1
= -5

13
Subtraction
A – B = A + (-B) = A + (B’ + 1)
find
001100 001100 101100 101100
- 010101 101011 - 010101 101011
---------------------------------------------- ------------------------------------------
110111 1 010111
B’=101010 Carry
B’+1= 101010
+1

14
Overflow
when an arithmetic operation produces a result that is out of range
Overflow

Remember:
range of Unsigned numbers: 0 to 2n-1
range of signed numbers: -2n-1 to +2n-1 -1

15
Overflow Unsigned Numbers
when an arithmetic operation produces a result that is out of range
Overflow Unsigned Addition
Example: in a 4 bit unsigned register add 5 to 4, the expected result is 9

Notice the carry out bit cn = 0


0 1 => No overflow in unsigned addition
0 1 0 0
0 1 0 1
-------------------------
1 0 0 1
The answer is 9 which is correct, there is no overflow

16
Overflow Unsigned Numbers
Example: in a 4 bit unsigned register add 6 to 14, the expected result is
20 that can not be represented by 4-bit unsigned register

1 1 1
0 1 1 0
Notice the carry out bit cn = 1
1 1 1 0
=> overflow in unsigned addition
-------------------------
0 1 0 0

The answer is 4 which is


wrong => Overflow

17
Overflow Unsigned Numbers
Example: in a 4 bit unsigned register subtract 6 from 14, the expected
result is 8 that can be represented by 4-bit unsigned register

Notice the carry out bit cn = 1


1 1 1
=> No overflow in unsigned subtraction
1 1 1 0 1 1 1 0
- 0 1 1 0 + 1 0 1 0
------------------------- -------------------------
1 0 0 0

A=0110 The answer is 8 which is


A’=1001 correct => No Overflow
A’+1 =
1001
1
18
1010
Overflow Unsigned Numbers
Example: in a 4 bit unsigned register subtract 14 from 6, the expected
result is negative that can not be represented by unsigned register

Notice the carry out bit cn = 0


0 1 1
=> Overflow in unsigned subtraction
0 1 1 0 0 1 1 0
- 1 1 1 0 + 0 0 1 0
------------------------- -------------------------
1 0 0 0

The answer is 8 which is


wrong => Overflow

19
Overflow Signed Numbers
when an arithmetic operation produces a result that is out of range
Overflow
Note: we talk about overflow when we work with signed registers

Example: in a 4 bit signed register add 5 to 4, the expected result is +9


0 1
0 1 0 0
0 1 0 1
-------------------------
1 0 0 1
The answer is -7 which is wrong, there is an overflow
as +9 can not be represented by 4-bit signed numbers
20
Overflow Signed Numbers
Example: in a 4-bit register add (-5) to (-4) Remember the previous
example with overflow:
1 0
1 0 1 1
1 1 0 0
-------------------------
0 1 1 1

The answer is +7 which is wrong, again -9


can not be represented in 4-bit registers
=> overflow
Notice in both cases we have the
carry out cn is different from cn-1

21
• 5 = 0101
• 5’= 1010
• 5’+1 = 1011 = -5 (2’s complement of 5)
• 4=0100
• 4’=1011
• 4’+1= 1100 = -4 (2’s complemen t of 4)

22
Overflow Signed Numbers
Add +5 to -4 in 4-bit signed register
1 1
0 1 0 1 The answer is + 1 which is correct, notice that
1 1 0 0 the carry out cn=cn-1 =1 => no overflow
-------------------------
0 0 0 1

23
Overflow Signed Numbers
Subtract 5 from 1 in 4-bit signed register (i.e 1-5=1+(-5) )
0 0 1 1
0 0 0 1 The answer is -4 which is correct, notice that
1 0 1 1 the carry out cn=cn-1 =0 => no overflow
-------------------------
1 1 0 0

24
Overflow
• Unsigned numbers:
• Addition
• Carry out =1 => Overflow
• Carry out = 0 => No overflow
• Subtraction
• Carry out = 1 => No overflow
• Carry out = 0 => Overflow
• Signed numbers:
• Addition/Subtraction:
• Carry out = Carry out -1 => No overflow
• Carry out and Carry out -1 are different => Overflow

25
Larger registers
Consider a 4-bit signed register holding the value 4.
0100
-6: 1010 using 4-bits signed register
• Copy this value to an 8-bit signed register Copy 1010 on 6-bits signed register
00000100 111010 =-32 + 16 + 8 + 2 =-6
-32 16 8 4 2 1
Consider a 4-bit signed register holding the value -4.
1100
• Copy this value to an 8-bit signed register
11111100

26
Range of a register in binary
• Range of an 8-bit unsigned register: 0 to 28-1, i.e., 0 to 255
• In binary range of an 8-bit unsigned register:
0 0 0 0 0 0 0 0 to 1 1 1 1 1 1 1 1
• Range of an 8-bit signed register: -27 to +27-1, i.e., -128 to +127
• In binary range of an 8-bit signed register:
1 0 0 0 0 0 0 0 to 0 1 1 1 1 1 1 1

27
The end
Done with chapter 1
Please send your questions related to this lecture on google classroom
Exercises to follow

28

You might also like