0% found this document useful (0 votes)
29 views36 pages

Part 1-Binary Representation

The document covers fixed point and floating point arithmetic operations, detailing how numbers are represented in binary systems. It explains signed magnitude, 1's complement, and 2's complement representations for both positive and negative integers, along with examples of binary subtraction and addition. Additionally, it discusses overflow and underflow in arithmetic operations, including conditions for detecting these errors.
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)
29 views36 pages

Part 1-Binary Representation

The document covers fixed point and floating point arithmetic operations, detailing how numbers are represented in binary systems. It explains signed magnitude, 1's complement, and 2's complement representations for both positive and negative integers, along with examples of binary subtraction and addition. Additionally, it discusses overflow and underflow in arithmetic operations, including conditions for detecting these errors.
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
You are on page 1/ 36

BCSE205L – Computer

Organization and Architecture


Module 2-Part 1

1
Topics to be covered
• Fixed point Arithmetic operations
• Overflow and Underflow

2
Fixed Point Arithmetic
• ALU is responsible for performing arithmetic and logic operations
• Based on the number system two basic data types are implemented
in the computer system.
• Fixed point numbers
• Floating point numbers
• In integers, radix point is fixed and assumed to be to the right of the
right most digit. As the radix point is fixed, the number system is
referred to as fixed point number system

3
Floating Point Arithmetic
• Floating point number system allows the representation of numbers
having both integer part and fractional part
• Since the position of the binary point in a floating-point number
varies, it must be indicated explicitly in the representation.
• binary floating-point number can be represented by:
• a sign for the number
• some significant bits
• a signed scale factor exponent for an implied base of 2

4
Fixed Point Arithmetic
• Consider an n-bit vector

• where bi = 0 or 1 for 0 ≤ i ≤ n − 1. This vector can represent an


unsigned integer value V(B) in the range 0 to 2n − 1, where

• We need to represent both positive and negative numbers. Three


systems are used for representing such numbers:
• Signed Magnitude Representation
• 1’s-complement Representation
• 2’s-complement Representation

5
a. Signed Magnitude Representation

• Leftmost bit is 0 for positive numbers and 1 for negative numbers


• If MSB = 1, the number is negative and if MSB=0, the number is positive. The remaining
bits represent magnitude.
• +43 and – 43 are represented as follows

6
Drawbacks of Signed Magnitude Representation

• addition and subtraction require a consideration of both the signs of


the numbers and their relative magnitudes to carry out the required
operation.
• There are two representations of 0

7
b. 1’s complement representation

• negative values are obtained by complementing each bit of the


corresponding positive number.
• The same operation, bit complementing, is done to convert a
negative number to the corresponding positive value.
• Ex: 1’s complement of 11010100 = 00101011

8
c. 2’s complement representation

• Obtained by adding 1 to 1’s complement


• 2’s complement = 1’s complement +1
• 2’s complement form is used to represent negative numbers
• Ex: 2’s complement of 11010100 = 00101100

9
Binary Subtraction using 2’s complement
• Negative number is represented in 2’s complement form and actual
addition is performed to get the desired result.
• Ex : A-B
• Take 2’s complement of B
• Add 2’s complement of B to A
• If carry is generated then the result is positive and in the true form. In this
case carry is ignored.
• If carry is not generated then the result is negative an in the 2’s complement
form
Binary Subtraction using 2’s complement
• 15 – 28 using 6 bit 2’s complement representation
15 = 001111
28 = 011100
-28 = 2’s complement of +28
= 100100
15 -28 = 15 + 2’s complement representation of -28
001111
100100(+)
110011
-----------
- No carry generated
- Result is negative and in 2’s complement form(-Result i.e. – (13))
i.e. negative of 000011(+13)
Binary Subtraction using 2’s complement
• 28 – 15 using 6 bit 2’s complement representation
28 = 011100
15 = 001111
-15 = 2’s complement of +15
= 110001
28 -15 = 28 + 2’s complement representation of -15
011100
110001(+)
1 001101
-----------
- ignore the carry
- 001101 is the binary equivalent of +13
Sample Problem-1
Subtract 82-64 using signed magnitude, 1’s complement, and 2’s
complement representations.
Step 1: first represent both numbers in binary form.
82 in binary (positive): 01010010​
64 in binary (positive): 01000000
Step 2: Signed Magnitude Representation
In signed magnitude representation, the most significant bit (MSB)
represents the sign (0 for positive, 1 for negative).
82 in binary (positive): 01010010​
64 in binary (positive): 01000000
• Subtraction using signed magnitude:
• Subtract 64 from 82: 01010010 -01000000= 000100102=18 10

13
Sample Problem-1 (contd…)
Step 3: 1’s complement representation
In 1's complement representation, the negative of a number is obtained by flipping all the
bits.
82 in 1's complement (positive):01010010
64 in 1's complement (positive):01000000
(No need to flip bits since both numbers are positive)
Subtraction using 1's complement:
Subtract 64 from 82: 01010010 -01000000= 000100102=18 10
Step 4: 2’s complement representation
In 2's complement representation, the negative of a number is obtained by flipping all the
bits and adding 1.
• In this example, both 82 and 64 are positive. So, directly subtract. No need to find 2’s complement
separately.
• Subtract 64 from 82: 01010010 -01000000= 000100102=18 10

14
Sample problem 2

• Subtract 20-50 using signed magnitude, 1’s complement, and 2’s complement representations.
Step 1: first represent both numbers in binary form.
20 in binary (positive): 00010100
50 in binary (positive): 00110010
Step 2: Signed Magnitude Representation
In signed magnitude representation, the most significant bit (MSB) represents the sign (0 for
positive, 1 for negative).
20 in binary (positive): 00010100
50 in binary (negative): 10110010 (The MSB is 1 because it's negative)
Since 20−50 is negative, we need to subtract 50 from 20 in magnitude and keep the result
negative.
00110010 -00010100= 00111110
• So, X in signed magnitude is 101111102 = - 3010

15
Sample Problem-2 (contd…)
Step 3: 1’s complement representation
In 1's complement representation, the negative of a number is obtained by flipping
all the bits.
20 in 1's complement (positive): 00010100
50 in 1's complement (negative): 11001101
Subtraction using 1's complement:
• Subtraction using 1's complement:
• Add the 1's complement of 50 to 20: 00010100 + 11001101 =11100001
• Since there is no carry, the result is negative in 1's complement, so flip the bits to get the
magnitude:
• X=00011110 = - 3010

16
Sample Problem-2 (contd…)

Step 4: 2’s complement representation


In 2's complement representation, the negative of a number is obtained by flipping
all the bits and adding 1.
• 20 in 2's complement (positive): 00010100
• 50 in 2's complement (negative): 11001110
• Subtraction using 2's complement:
• Add the 2's complement of 50 to 20:
• 00010100 + 11001110 =11100010= -3010

17
Why 2’s complement?

18
Signed Binary Numbers

19
Binary addition for 2 bits

20
Binary Addition using 2’s complement
• Case 1: Addition of the positive number with a negative number
when the positive number has a greater magnitude.
• Initially find the 2's complement of the given negative number. Sum
up with the given positive number. If we get the end-around carry 1
then the number will be a positive number and the carry bit will be
discarded and remaining bits are the final result.

21
Binary Addition using 2’s complement
• Case 2: Adding of the positive value with a negative value when the
negative number has a higher magnitude.
• Initially, add a positive value with the 2's complement value of the
negative number. Here, no end-around carry is found. So, we take the
2's complement of the result to get the final result.

22
Binary Addition using 2’s complement
• Case 3: Addition of two negative numbers

• Take 2’s complement of both numbers and perform addition.


• In this case, first, find the 2's complement of both the negative
numbers, and then we will add both these complement numbers. In
this case, we will always get the end-around carry, which will be
added to the LSB, and forgetting the final result, we will take the2's
complement of the result.

23
Binary Addition using 2’s complement

24
Error detection
Overflow and underflow
• Using 2’s-complement representation, n bits can represent values in
the range -2n-1 to +2n-1 – 1
• For example, the range of numbers that can be represented by 4 bits
is −8 through +7
• When the actual result of an arithmetic operation is outside the
positive representable range, an arithmetic overflow has occurred.

25
Error detection-Overflow and underflow
• It occurs when the signs of the two operands are the same, but the
sign of the result is different. Therefore, a circuit to detect overflow
can be added to the n-bit adder by implementing the logic expression

• It can also be shown that overflow occurs when the carry bits Cn and
Cn-1 are different

26
Overflow and Underflow
Carry Sign Overflow/Underflow

0 0 No Underflow/Overflow

1 1 No Underflow/Overflow

0 1 Underflow

1 0 Overflow

27
Overflow example
• Add 11 and 6
• +11 = 0 1 0 1 1
• +6 = 0 0 1 1 0 (+)
• -------------
• 10001
• Sign bit of the input and output are different . Hence overflow has
occurred.
• Since with 5 bits, we can represent -16 to +15. But 11+6 = +17 which can
not be represented by 5 bits using signed bit representation
• Carry into the sign bit is 1 and carry out of sign bit addition is 0. Hence
overflow occurred

28
Overflow and Underflow
• Overflow occurs when an arithmetic operation yields a result that is
greater than the range’s positive limit of +2n-1 – 1
• Underflow occurs when an arithmetic operation yields a result that is
less than the range’s negative limit of -2n-1

29
Example

30
31
Carry and Overflow

32
Carry and Overflow

33
Carry and Overflow

34
Carry and Overflow

35
36

You might also like