0% found this document useful (0 votes)
19 views29 pages

Digital Arithmetic Operations

Uploaded by

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

Digital Arithmetic Operations

Uploaded by

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

Digital

Arithmetic:
Operations
Topic Outcome
• Describe how negative number is represented in a computer system

• Describe the 2’s complement number system

• Perform operations that include negative numbers using the 2’s complement
representation
Signed and Unsigned Binary Numbers
• integer variables are represented in a signed and unsigned manner

• positive and negative values are differentiated by using the sign flag in signed numbers
• unsigned numbers do not use any flag for the sign, i.e., only positive numbers can be stored by the
unsigned numbers.

• our day-to-day life


• positive numbers without adding any sign before them
• negative number with - (minus) sign before them

• digital system
• not possible to use negative sign before them because the data is in binary form in digital computers
• require a special notation representing the sign in binary numbers
Binary Numbers Representation
• computer can understand only (0, 1) language

• binary numbers are represented in both ways, i.e., signed and unsigned
• positive numbers are represented in both ways: signed and unsigned
• negative numbers can only be described in a signed way
• difference between unsigned and signed numbers is that unsigned numbers do not use any sign bit
for positive and negative numbers identification, but the signed number used
Binary Numbers Representation
Binary Number
Representation

Only for positive Unsigned Signed For both positive and


numbers Representation Representation negative numbers
Unambiguous
(only one 0) Signed- Ambiguous
Magnitude form (two 0’s)

1’s complement Ambiguous


form (two 0’s)

2’s complement Unambiguous


form (only one 0)
Unsigned Numbers
• don't have any sign for representing negative numbers
• always positive
• no sign bit in unsigned binary numbers so it can only represent its magnitude
• in zero and one
• zero is an unsigned binary number and is only one zero (0) in this representation, which is always
positive
• one unique binary equivalent form of a number in unsigned number representation - known as
unambiguous representation technique
• range of the unsigned binary numbers starts from 0 to (2 n-1)
Unsigned Numbers
• Ex: Represent the decimal number 28 in unsigned 2 ) 28
binary numbers 2 ) 14 0
• change this decimal number into binary, which has the 2 ) 7 0
only magnitude of the given name 2 ) 3 1
• 2810 = 111002, a 5-bit magnitude 2 1 1
Unsigned Numbers
• Ex: Find range of 5-bit unsigned binary numbers. 2 ) 28
Also, find minimum and maximum value in this 2 ) 14 0
range. 2 ) 7 0
• range of unsigned binary number is from 0 to (2n-1) 2 ) 3 1
• range of 5-bit unsigned binary number is from 0 to (2 -
5
2 1 1
1)
• minimum value 0 (i.e., 00000) to maximum value 31
(i.e., 11111)
Signed Numbers
• have a sign bit so that it can differentiate positive and negative integer numbers

• has both the sign bit and the magnitude of the number
• representing the negative decimal number, the corresponding symbol in front of the binary number
will be added

• zero in signed representation


• signed bit makes two possible representations of zero (positive (0) and negative (1)), which is an ambiguous
representation
• no double representation of zero is possible, which makes it unambiguous representation
Signed Numbers
• 3 ways of representation
• Signed-Magnitude form
• a binary number has a bit for a sign symbol
• bit is set to 1, the number will be negative else the number will be positive if it is set to 0
• n-1 bits represent the magnitude of the number.

• 1's Complement
• inverting each bit of a number to obtain the 1's complement of a number
• negative numbers can be represented in the form of 1's complement
• binary number also has an extra bit for sign representation as a sign-magnitude form.

• 2's Complement
• inverting each bit of a number and adding plus 1 to its least significant bit
• negative numbers can also be represented in the form of 2's complement
• binary number also has an extra bit for sign representation as a sign-magnitude form
Signed-Magnitude form
• for n bit binary number, 1 bit is reserved for sign symbol
Positive singed-magnitude
• value of sign bit is 0, then the given number will be positive
• value of sign bit is 1, then the given number will be negative
• remaining (n-1) bits represent magnitude of the number.
• magnitude of number zero (0) is always 0, so there can be two
representation of number zero (0), positive (+0) and negative (-0), which Negative singed-magnitude
depends on value of sign bit - ambiguous representation
• sign bit is a most significant bit (MSB) of representation
• range of sign-magnitude form is from -(2(n-1)-1) to (2(n-1)-1)
Signed-Magnitude form
• Ex: 6-bit Signed-Magnitude form
• range of 6-bit Sign-Magnitude form binary number is from -(25-1) to (25-1)
• from minimum value -31 (i.e., 1 11111) to maximum value +31 (i.e., 0 11111)
• zero (0) has two representation, -0 (i.e., 1 00000) and +0 (i.e., 0 00000)
Signed-Magnitude form
• MSB is used, 1 = negative and 0 = positive, the rest are the same
• clear and easy to implement
• Note: operations do not conform to the standard arithmetic rules, as in:

0000 0110 =+ 6
+ 1000 0110
1000 1100
=- 6
= - 12 X
1’s complement
• obtained by inverting each bit of given number
• represent positive numbers in binary form and negative numbers in 1’s complement form
• there is extra bit for sign representation
• value of sign bit is 0, then number is positive - directly represent it in simple binary form
• value of sign bit 1, then number is negative and have to take 1’s complement of given binary
number
• can get negative number by 1’s complement of a positive number and positive number by using 1’s
complement of a negative number
• zero (0) can have two representation, that’s why 1’s complement form is also ambiguous form
• range of 1’s complement form is from -(2(n-1)-1) to (2(n-1)-1)
1’s complement
• Ex: 6-bit 1’s complement form
• range of 6-bit 1’s complement form binary number is from -(25-1) to (25-1)
• minimum value -31 (i.e., 1 00000) to maximum value +31 (i.e., 0 11111)
• zero (0) has two representation, -0 (i.e., 1 11111) and +0 (i.e., 0 00000)
1’s complement
• Subtraction of 2 8-bit binary numbers • 01010111 (the overflow “1” cancels out)
• 11510 in binary is: 011100112 • convert it back from a 1’s complement answer to the real
answer, need add “1” to the 1’s complement result
• 2710 in binary is: 000110112
• 115 – 27 = 115 + (-27) = 88 01010111
• 1’s completement of 27: +1
• Invert 00011011 => 11100100
01011000
01110011 • 010110002 or (64 + 16 + 8) = 8810 in decimal
+ 11100100
Overflow → 1 01010111
Ignore the 9-bit
2’s complement
• obtained by inverting each bit of given number and plus 1 to least significant bit (LSB)
• represent positive numbers in binary form and negative numbers in 2’s complement form
• extra bit for sign representation
• value of sign bit is 0, then number is positive and can directly represent it in simple binary form
• value of sign bit 1, then number is negative and have to take 2’s complement of given binary
number
• can get negative number by 2’s complement of a positive number and positive number by directly
using simple binary representation
• value of most significant bit (MSB) is 1, then take 2’s complement from, else not
• zero (0) has only one (unique) representation which is always positive.
• range of 1’s complement form is from -2(n-1) to (2(n-1)-1)
2’s complement
• Ex: 6-bit 2’s complement form
• range of 6-bit 2’s complement form binary number is from -25 to (25-1)
• minimum value -32 (i.e., 1 00000) to maximum value +31 (i.e., 0 11111)
• zero (0) has one representation, 0 (i.e., 0 00000)
2’s complement
• Ex: Find the 2’s complement expression of -3510
2’s complement
• Ex: Find the 2’s complement expression of -3510
• 3510 = 0010 00112
• flip each of the bits above
• add 1

1’s
= 1 1 0 1 1 1 0 0
complement
add 1 = 0 0 0 0 0 0 0 1
2’s
1 1 0 1 1 1 0 1
complement
2’s complement
• Subtraction of 2 binary numbers • 01011000 (the overflow “1” cancels out)
• 11510 in binary is: 011100112 • convert it back from a 2’s complement answer
• 010110002 or (64 + 16 + 8) = 8810 in decimal
• 2710 in binary is: 000110112
• 115 – 27 = 115 + (-27) = 88
• 2’s completement of 27
• Invert 00011011 => 11100100
• 11100100 + 1 = 11100101
01110011
+ 11100101
Overflow → 1 01011000
Ignore the 9-bit
2’s complement
• Ex: using 8-bit 2’s complement numbers.
• Add −8 to +3

• Add −5 to −2
2’s complement
• Ex: using 8-bit 2’s complement numbers.
• Add −8 to +3 8 => 0000 1000
(+3) 0000 0011 Invert => 1111 0111
Add 1 =>+ 1
+(−8) 1111 1000
1111 1000
------------------------
(−5) 1111 1011 => -ve in 2’s complement, invert => 0000 0100, add 1 => 0000 0101, 4 + 1 = 5, so, is -5

• Add −5 to −2
(−2) 1111 1110
+(−5) 1111 1011
------------------------
(−7) 1 1111 1001 : discard carry-out => -ve in 2’s complement, invert => 0000 0110,
add 1 => 0000 0111, 4+2+1 = 7, so, is -7
2’s complement
• Ex: using 4-bit 2’s complement numbers.
• Add −7 to -3

• Add −5 to −2
2’s complement
• Ex: using 4-bit 2’s complement numbers.
• Add −7 to -3
(−3) 1101
+(−7) 1001
------------------------
(−10) 1 0110 : discard carry-out, 0110 => 4 + 2 = 6??

• Add −5 to −2
(−2) 1110
+(−5) 1011
------------------------
(−7) 1 1001: discard carry-out, -ve in 2’s complement, 1001 => invert 0110 => 0110 + 1 = 0111, 7
2’s complement - Overflow Rule for addition
• 2 Two's Complement numbers are added, and they both have the same sign (both positive or both negative),
then overflow occurs if and only if the result has the opposite sign
• Overflow never occurs when adding operands with different signs.
• Means
• Adding two positive numbers must give a positive result
• Adding two negative numbers must give a negative result

• Overflow occurs if
• (+A) + (+B) = −C
• (−A) + (−B) = +C

• Example: Using 4-bit Two's Complement numbers (−8 ≤ x ≤ +7)


(−7) 1001
+ (−6) 1010
-----------------
(−13) 1 0011 = 3 : Overflow (smallest negative number is −8)
2’s complement - Overflow Rule for subtraction
• 2 Two's Complement numbers are subtracted, and their signs are different, then overflow occurs if and only if
the result has the same sign as the subtrahend.
• Overflow occurs if
• (+A) − (−B) = −C
• (−A) − (+B) = +C

• Example: Using 4-bit Two's Complement numbers (−8 ≤ x ≤ +7)


• Subtract −6 from +7
(+7) 0111 0111
−(−6) 1010 -> Negate -> +0110
---------- ---------
13 1101 = −8 + 5 = −3 : Overflow
4-bit Signed Binary Number
Signed One’s Signed Two’s
Decimal Signed Magnitude
Complement Complement

+7 0111 0111 0111


+6 0110 0110 0110
+5 0101 0101 0101
+4 0100 0100 0100
+3 0011 0011 0011
+2 0010 0010 0010
+1 0001 0001 0001
+0 0000 0000 0000
-0 1000 1111 –
-1 1001 1110 1111
-2 1010 1101 1110
-3 1011 1100 1101
-4 1100 1011 1100
-5 1101 1010 1011
-6 1110 1001 1010
-7 1111 1000 1001
Reference:
• https://www.javatpoint.com/signed-and-unsigned-binary-numbers-in-digital-electronics

• https://www.tutorialspoint.com/unsigned-and-signed-binary-numbers
• https://www.electronics-tutorials.ws/binary/signed-binary-numbers.html
• https://www.doc.ic.ac.uk/~eedwards/compsys/arithmetic/index.html

You might also like