0% found this document useful (0 votes)
42 views

ITU07102.Lecture.5-Signed Number and BCD

Uploaded by

witnessstanley07
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

ITU07102.Lecture.5-Signed Number and BCD

Uploaded by

witnessstanley07
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Signed Numbers

1’s Complement & 2’s Complement

 Binary Coded Decimals (BCD)


Signed Numbers

 To make a number negative in decimal (Base 10), we

simply attach a minus sign (-) to the front of a number

 For example: -0.3610 or -5210

 With computers that can only work with ones and

zeros, we need to modify this approach slightly.


Signing a binary number
 We add an extra digit to the front of our binary number to indicate
whether the number is positive or negative.
 In computer terminology, this digit is called a sign bit.
 For a positive number, we make our sign bit zero, and for a
negative number, we make our sign bit one.
• This approach is called the Signed Magnitude Representation.

Note: This is very similar to adding a minus sign in decimal


number
Example
 Let's convert the decimal numbers -610 and -110 to binary
using Signed Magnitude Representation.
 For these numbers, four bits will be enough to represent both.
 It is a 4-bit signed magnitude representation, on which the
first bit is our sign and the remaining three bits are our
number

For positive: 6 will be 0110 and 1 will be 0001

To make our binary numbers negative, we simply change our sign


bit from '0' to '1‘ . 1110 (-6) and 1001 (-1)
Example
 Write the number -710 in signed magnitude

representation using 5 bits.

 Solution:
• First, we write 710 in binary using 5 bits:
001112.
• Next, we change our sign bit from 0 to 1
to make the number negative: 101112.
Arithmetic issues with signed magnitude
While representing negative numbers with signed magnitude is simple,
performing arithmetic with signed magnitude is difficult. What we would really
like to have is a way of representing signed numbers that simplifies our binary
arithmetic.

Suppose we could represent signed numbers in such a way that all our
computations could be completed using only addition. This would allow our
computer processor to perform all arithmetic operations with only addition
circuitry.

It’s well known that multiplication is really repeated addition, so this is not a
problem.

Division and Subtraction. Division is just repeated subtraction. Now, how can
we convert our subtraction problems to addition?
For example: Consider the subtraction problem 3010 - 710.
• This problem can be converted into an equivalent addition
problem by changing 710 to -710.

• Now, this problem can be stated as 3010 + (-710) = 2310.


• This approach can be transferred to binary by representing
negative numbers as complements.
• Next is the two ways of representing signed numbers using
complements: 1's complement and 2's complement.
One’s Complement
 Representing a signed number with 1's complement is done by
changing all the bits that are 1 to 0 and all the bits that are 0 to 1.

 Reversing the digits in this way is also called complementing a


number.
 Example: Let's look at a 4-bit arithmetic. How can we
represent the number -510 in 1's complement?

• First, we write the positive value of the number in binary. 0101


(+5)

• Next, we reverse each bit of the number so 1's become 0's and
0's become 1's 1010 (-5)
A quick summary of how to find the 1's complement
representation of any decimal number x.

1. If x is positive, simply convert x to binary.

2. If x is negative, write the positive value of x in binary

3. Reverse each bit.


Tutorial Question:

Write the 1's complement for each of the following 5-bit


binary numbers.
a. 010012

b. 010112

c. 001112

d. 000012
Two’s Complement
 Representing a signed number with 2's complement is done by
adding 1 to the 1's complement representation of the number.
 To illustrate, let's look at the same example we used for 1's
complement.
 How can we represent the number -510 in 2's complement using
4-bits?

1. First, we write the positive value of the number in binary. 0101


(+5)
2. Next, we reverse each bit to get the 1's complement. 1010
3. Last, we add 1 (i.e. 0001) to the number 1010. 1011 (-5)
A quick summary of how to find the 2's complement
representation of any decimal number x.

Notice the first three steps are the same as 1's complement.

1. If x is positive, simply convert x to binary.


2. If x is negative, write the positive value of x in binary
3. Reverse each bit.
4. Add 1 to the complemented number.
Tutorial Questions
Part-1: Write the 2's complement for each of the following 5-bit
binary numbers.
a. 010012
b. 010112
c. 001112
d. 000012

Part-2: Convert the following decimal numbers to binary using 6-


bit 2's complement representation.
a. -1610
b. 1310
c. -310
d. -1010
e. 2610
f. -3110
Answers for Part-2
The 2's complement representation for each number is given below.

1. 1100002
2. 0011012
3. 1111012
4. 1101102
5. 0110102
6. 1000012
Subtraction with Signed Numbers
Using 1’s Complement in Subtraction
Summary of the steps for subtracting x from y with an n-bit 1's
complement representation.
1. Negate x using 1's complement.
Reverse all the bits in x to form -x.
2. Add -x and y.
3. If the sum exceeds n bits (overflowing bit), add the extra
bit (overflowing bit) to the result.
4. If the sum does not exceed n bits, leave the result as it is.
Solve each of the following 5-bit subtraction problems using 1's complement
representation.
a. 001102 – 001012
b. 011002 - 010102
c. 001002 - 001012
d. 010012 - 010112
e. 000112 - 011002
f. 001102 - 010012

For each part, the correct 1's complement representation of the subtrahend is
given first followed by the answer.
a. 110102; 000012
b. 101012; 000102
c. 110102; 111102
d. 101002; 111012
e. 100112; 101102
f. 101102; 111002
Using 2’s Complement in Subtraction

Summary of the steps for subtracting x from y with an n-bit 2's


complement representation.
1. Negate x using 2's complement.
Reverse all the bits in x.
Add 1 to form -x.
2. Add -x and y.
3. Discard any bits greater than n (overflowing bit).
Solve each of the following 5-bit subtraction problems using 2's complement
representation.
a. 001102 – 001012

b. 011012 – 010012

c. 010002 – 000112

d. 011102 – 011002

For each part, the correct 2's complement representation of the subtrahend is
given first followed by the answer.
a. 110112; 000012

b. 101112; 001002

c. 111012; 001012

d. 101002; 000102
Binary Coded Decimals (BCD)
Binary Coded Decimals
When numbers, letters, or words are represented by a special a
special group of symbols, we say they are being coded, and the
group of symbols is called code.

Binary coded Decimals a system for coding a number in which each


digit of a decimal number is represented individually by its binary
equivalent

 In four bit system, we have seen that any decimal number (0-9)
can be represented by equivalent binary numbers (see table).
Note: The group of 0s and 1s in the binary number can be thought as
a code representing the decimal number.

 When a decimal number is represented by its equivalent


binary number, we call it straight binary code
0000 0
0001 1
Table for 4-bit system
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
Why BCD: Digital systems uses binary number in their
operations, but the external world in decimal in nature. So, BCD is
a way of trying to minimize the conversion from Decimal to
Binary and vice versa.

Example: 874 = 1000 0111 0100


Example: 943 = 1001 0100 0011

 Each decimal digit is changed to its straight binary


equivalent.

Note: BCD only uses Four-bit binary numbers from 0000 through
1001BCD does not use the numbers 1010, 1011, 1100, 1101, 11101
and 1111 - these are called "Forbidden" four-bit patterns in BCD. If
it happened, means an error.
Example: Convert 0110100000111001 (BCD) to is decimal

equivalent.

Answer: 0110 1000 0011 1001 = 6 8 3 9

Example: Convert 011111000001

Answer: 0111 1100 0001 = 7 forbidden bit pattern 1


Note: BCD is not another number system like Binary, Octal,
Decimal, and Hexadecimal. It is the decimal system with each
digit encoded in its binary equivalent.
Note: BCD is not the same as straight binary number, which take a
complete decimal number and represent it in binary
Example: 137 = 10001001 (Binary)
Example: 137 = 0001 0011 0111 (BCD)

 Here: BCD code requires 12 bits while straight binary requires


8 bits to represent 137. Hence, BCD requires more bits.

 The main advantage of BCD code is the relative ease of


converting to and from decimal
Tutorial Questions:

1. Represent the decimal value 178 by its straight binary


equivalent. The encode the same decimal number using BCD.
2. How many bits are required to represent an eight-digit decimal
number in BCD?
3. What is an advantage of encoding a decimal number in BCD as
compared to straight binary? What is a disadvantage?
The Byte:
Most computer handle and store binary data and information in a
group of eight bits, so a special name is given to a string of eight
bits: It is called a byte.
 A Byte can represent any of numerous types of data or
information.
 Nible: It’s a group of 4 bits
Examples on Bytes
1. How many bytes are in a 32-bit string?
2. What is the largest decimal value that can be represented in
binary using two bytes?
3. How many bytes are needed to represent the decimal value 846,
569 in BCD?
4. How many bytes are needed to represent 235 in binary?
Next: Logic gates

You might also like