Representation
About
1 byte comprises of 8 bits and any integer or character can be represented using bits in computers, which we call its binary form(contains only 1 or 0) or in its base 2 form.
Example:
In general, the binary number can be represented in two ways.
Unsigned Binary Numbers
Signed Binary Numbers
Unsigned Binary Numbers
Using unsigned binary number representation, only positive binary numbers can be represented. For n-bit unsigned binary numbers, all n-bits are used to represent the magnitude of the number.
For example, if we represent decimal 12 in 5- bit unsigned number form then (12)10 = (01100)2. Here all 5 bit are used to represent the magnitude of the number
Signed Binary Numbers
Using signed binary number representation both positive and negative numbers can be represented.
In signed binary number representation the most significant bit (MSB) of the number is a sign bit. For positive numbers, the sign bit is 0 and for negative number, the sign bit is 1.
There are three different ways the signed binary numbers can be represented.
Signed Magnitude Form
1’s Complement Form
2’s Complement Form
Sign Magnitude Representation
In sign-magnitude representation, the Most Significant bit of the number is a sign bit and the remaining bit represents the magnitude of the number in a true binary form. For example, if some signed number is represented in the 8-bit sign-magnitude form then MSB is a sign bit and the remaining 7 bits represent the magnitude of the number in a true binary form.
Here is the representation of + 34 and -34 in a 8-bit sign-magnitude form.
Since the magnitude of both numbers is the same, the first 7 bits in the representation are the same for both numbers. For +34, the MSB is 0, and for -34, the MSB or sign bit is 1.
Using n-bits, the range of numbers that can be represented in Sign Magnitude Representation is from – (2^(n-1) – 1) to (2^(n -1) – 1).
Positive range:
0
to(2^(n-1) - 1)
Negative range:
-1
to-(2^(n-1) - 1)
1’s Complement Representation
In 1’s complement representation, the representation of the positive number is same as the negative number. But the representation of the negative number is different.
For example, if we want to represent -34 in 8-bit 1’s complement form, then first write the positive number (+34). And invert all 1s in that number by 0s and 0s by 1s in that number. The corresponding inverted number represents the -34 in 1’s complement form. It is also called 1s complement of the number +34.
Using n-bits, the range of numbers that can be represented in 1’s complement form is from – (2^(n-1) – 1) to (2^(n -1) – 1).
2’s Complement Representation
In 2’s complement representation also, the representation of the positive number is same as 1’s complement and sign-magnitude form.
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.
Find 1’s complement of +34
Add ‘1’ to the 1’s complement number
The resultant is 2’s complement representation of -34
Comparison
Feature
Sign Magnitude Representation
1st Complement
2nd Complement
Representation of Sign
The most significant bit (MSB) represents the sign:
0
for positive, 1
for negative.
MSB represents the sign, similar to Sign Magnitude.
MSB represents the sign, similar to Sign Magnitude.
Positive Numbers
Represented as usual binary. Example: +5
in 4-bit: 0101
.
Represented as usual binary. Example: +5
in 4-bit: 0101
.
Represented as usual binary. Example: +5
in 4-bit: 0101
.
Negative Numbers
Invert the MSB to 1
, rest is unchanged.
Example: -5
in 4-bit: 1101
.
Invert all bits of the positive number.
Example: -5
in 4-bit: 1010
.
Invert all bits of the positive number and add 1
.
Example: -5
in 4-bit: 1011
.
Zero Representation
Two representations: +0
(0000
) and -0
(1000
).
Two representations: +0
(0000
) and -0
(1111
).
Single representation: 0000
.
Arithmetic Operations
Requires separate handling of sign and magnitude.
Simple addition/subtraction but requires end-around carry for correctness.
Simplifies addition/subtraction, no need for special rules.
Range of Values
For n
bits:
-2^(n-1) + 1
to 2^(n-1) - 1
.
Positive:
0
to2^(n-1) - 1
.Negative:
-1
to-(2^(n-1) - 1)
.
For n
bits:
-2^(n-1) + 1
to 2^(n-1) - 1
.
Positive:
0
to2^(n-1) - 1
.Negative:
-1
to-(2^(n-1) - 1)
.
For n
bits:
-2^(n-1)
to 2^(n-1) - 1
.
Positive:
0
to2^(n-1) - 1
.Negative:
-2^(n-1)
to-1
.
Example (4 bits)
Positive range:
0000 (0)
to0111 (+7)
.Negative range:
1000 (-0)
to1111 (-7)
.Range:
-7
to+7
(but with two zeros,+0
and-0
).
Positive range:
0000 (0)
to0111 (+7)
.Negative range:
1111 (-0)
to1000 (-7)
.Range:
-7
to+7
(but with two zeros,+0
and-0
).
Positive range:
0000 (0)
to0111 (+7)
.Negative range:
1000 (-8)
to1111 (-1)
.Range:
-8
to+7
(no extra zeros).
Advantages
Simple to understand and implement.
Easy to compute negative values.
Ideal for arithmetic operations and eliminates ambiguity with zero.
Disadvantages
Complex arithmetic; two representations for zero.
Requires handling end-around carry.
Slightly more complex to compute negative values initially.
Last updated
Was this helpful?