0 likes | 7 Views
In computer systems, numbers are represented using binary digits (bits). Depending on the context, these numbers can be classified as signed or unsigned. Additionally, complement representations are used to simplify arithmetic operations, especially subtraction.
E N D
Signed and Unsigned Numbers and Complement Dr Anita Choudhary Assistant Professor Department of Computer Science anitach312@gmail.com
Unsigned Numbers • Unsigned numbers don't have any sign for representing negative numbers. • So the unsigned numbers are always positive. • We always assume a positive sign in front of each decimal digit. • There is no sign bit in unsigned binary numbers so it can only represent its magnitude. In zero and one, zero is an unsigned binary number. There is only one zero (0) in this representation, which is always positive. • The range of the unsigned binary numbers starts from 0 to (2^(n)-1).
Signed Numbers • The signednumbers have a sign bit so that it can differentiate positive and negativeintegernumbers. • The signed binary number technique has both the sign bit and the magnitude of the number. • For representing the negative decimal number, the corresponding symbol in front of the binary number will be added. • The signed bit makes two possible representations of zero (positive (0) and negative (1)), which is an ambiguous representation. • In 2's complement representation no double representation of zero is possible, which makes it unambiguous representation.
Signed Magnitude Method • If the number is positive then sign bit will be 0 and if number is negative then sign bit will be 1. • Magnitude is represented with the binary form of the number to be represented. • Example: Let we are using 5 bits register. The representation of -5 to +5 will be as follows:
1’s complement • 1’s complement of a binary number is another binary number obtained by toggling all bits in it, i.e., transforming the 0 bit to 1 and the 1 bit to 0. • In the 1’s complement format , the positive numbers remain unchanged . • The negative numbers are obtained by taking the 1’s complement of positive counterparts. • example +9 will be represented as 00001001 in eight-bit notation and -9 will be represented as 11110110, which is the 1’s complement of 00001001. +9 00001001 ↓1’s complement -9 11110110
1’s complement • Let numbers be stored using 4 bits 1's complement of 7 (0111) is 8 (1000) 1's complement of 12 (1100) is 3 (0011) • For finding 1's complement of the binary number, we can implement the logic circuit also by using NOT gate. We use NOT gate for each bit of the binary number. So, if we want to implement the logic circuit for 5-bit 1's complement, five NOT gates will be used.
2’s complement • 2’s complement of a binary number is 1, added to the 1’s complement of the binary number. • In 2’s complement representation of binary numbers, the MSB represents the sign with a ‘0’ used for plus sign and a ‘1’ used for a minus sign. • The remaining bits are used for representing magnitude. • Positive magnitudes are represented in the same way as in the case of sign-bit or 1’s complement representation. • Negative magnitudes are represented by the 2’s complement of their positive counterparts.
2’s Complement Representation of Positive Numbers • In 2’s complement representation also, the representation of the positive number is same as1’s complement and sign-magnitude form.
2’s Complement Representation of Negative Numbers • But the representation of the negative number is different. For example, if we want to represent -34 in 2’s complement form then • Write the number corresponding to +34. • Starting from Least Significant Bit (LSB), just copy all the bits until the first 1 is encountered in the number. • After the first ‘1’ is encountered, invert all the 1s in the number with 0s and 0s in the number with 1s (including the sign bit) • The resultant number is 2’s complement representation of the number -34.
2’s Complement Representation of Negative Numbers • The second way of representing -34 in 2’s complement form is • Write the number corresponding to +34. • Find 1’s complement of +34 • Add ‘1’ to the 1’s complement number • The resultant is 2’s complement representation of -34
Range of 1’s and 2’s complement • Range of 1’s complement for n bit number is from –(2^(n)-1)-1 to (2 ^(n)-1)-1 whereas the range of 2’s complement for n bit is from –(2^(n)-1) to (2^(n)-1)-1. • There are (2 ^(n)-1) valid numbers in 1’s complement and 2n valid numbers in 2’s complement.