Unit2 - Number System
Unit2 - Number System
In a digital system, the system can understand only the optional number system. In
these systems, digits symbols are used to represent different values, depending on the
index from which it settled in the number system.
In simple terms, for representing the information, we use the number system in the
digital system.
1. The digit
3. Finally, the base numbers, the total number of digits available in the number
system.
Note: When the number system represents a digit from 0 - 9, the base of the number will be
10.
Characteristics:
4. The position of the last digit represents the x power of the base(2). Example: 2 x,
where x represents the last position, i.e., 1
Examples:
The position in the decimal number system specifies the power of the base (10). The 0
is the minimum value of the digit, and 9 is the maximum value of the digit. For
example, the decimal number 2541 consist of the digit 1 in the unit position, 4 in the
tens position, 5 in the hundreds position, and 2 in the thousand positions and the value
will be written as:
Characteristics:
4. The position of the last digit represents the x power of the base(8). Example: 8 x,
where x represents the last position, i.e., 1
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
Examples:
the hexadecimal number system. The number system has a base of 16 means there
are total 16 symbols(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) used for representing a
number. The single-bit representation of decimal values10, 11, 12, 13, 14, and 15 are
represented by A, B, C, D, E, and F. Only 4 bits are required for representing a number
in a hexadecimal number. Each set of bits has a distinct value between 0 and 15. There
are the following characteristics of the octal number system:
Characteristics:
5. In hexadecimal number, the position of the last digit represents the x power of
the base(16). Example: 16x, where x represents the last position, i.e., 1
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
Examples:
As, we have four types of number systems so each one can be converted into the
remaining three systems. There are the following conversions possible in Number
System
Example 1: (10110.001)2
We multiplied each bit of (10110.001)2 with its respective positional weight, and last we
add the products of all the bits with its weight.
(10110.001)2=(1×24)+(0×23)+(1×22)+(1×21)+(0×20)+
(0×2-1)+(0×2-2)+(1×2-3)
(10110.001)2=(1×16)+(0×8)+(1×4)+(1×2)+(0×1)+
(0×1⁄2)+(0×1⁄4)+(1×1⁄8)
(10110.001)2=16+0+4+2+0+0+0+0.125
(10110.001)2=(22.125 )10
1. In the first step, we have to make the pairs of three bits on both sides of the
binary point. If there will be one or two bits left in a pair of three bits pair, we
add the required number of zeros on extreme sides.
2. In the second step, we write the octal digits corresponding to each pair.
Example 1: (111110101011.0011)2
1. Firstly, we make pairs of three bits on both sides of the binary point.
On the right side of the binary point, the last pair has only one bit. To make it a
complete pair of three bits, we added two zeros on the extreme side.
(111110101011.0011)2=(7653.14)8
2. In the second step, we write the hexadecimal digits corresponding to each pair.
Example 1: (10110101011.0011)2
1. Firstly, we make pairs of four bits on both sides of the binary point.
On the left side of the binary point, the first pair has three bits. To make it a complete
pair of four bits, add one zero on the extreme side.
(011110101011.0011)2=(7AB.3)16
1. In the first step, we perform the division operation on integer and successive
part with base 'r'. We will list down all the remainders till the quotient is zero.
Then we find out the remainders in reverse order for getting the integer part of
the equivalent number of base 'r'. In this, the least and most significant digits
are denoted by the first and the last remainders.
2. In the next step, the multiplication operation is done with base 'r' of the
fractional and successive fraction. The carries are noted until the result is zero or
when the required number of the equivalent digit is obtained. For getting the
fractional part of the equivalent number of base 'r', the normal sequence of
carrying is considered.
1. In the first step, we perform the division operation on the integer and the
successive quotient with the base of binary(2).
2. Next, we perform the multiplication on the integer and the successive quotient
with the base of binary(2).
Example 1: (152.25)10
Step 1:
Divide the number 152 and its successive quotients with base 2.
152/2 76 0 (LSB)
76/2 38 0
38/2 19 0
19/2 9 1
9/2 4 1
4/2 2 0
2/2 1 0
1/2 0 1(MSB)
(152)10=(10011000)2
Step 2:
Now, perform the multiplication of 0.27 and successive fraction with base 2.
0.50×2 0 1
(0.25)10=(.01)2
1. In the first step, we perform the division operation on the integer and the
successive quotient with the base of octal(8).
2. Next, we perform the multiplication on the integer and the successive quotient
with the base of octal(8).
Example 1: (152.25)10
Step 1:
Divide the number 152 and its successive quotients with base 8.
152/8 19 0
19/8 2 3
2/8 0 2
(152)10=(230)8
Step 2:
Now perform the multiplication of 0.25 and successive fraction with base 8.
0.25×8 0 2
(0.25)10=(2)8
1. In the first step, we perform the division operation on the integer and the
successive quotient with the base of hexadecimal (16).
2. Next, we perform the multiplication on the integer and the successive quotient
with the base of hexadecimal (16).
Example 1: (152.25)10
Step 1:
Divide the number 152 and its successive quotients with base 8.
152/16 9 8
9/16 0 9
(152)10=(98)16
Step 2:
Now perform the multiplication of 0.25 and successive fraction with base 16.
0.25×16 0 4
(0.25)10=(4)16
Let's take an example to understand how the conversion is done from octal to decimal.
Example 1: (152.25)8
Step 1:
We multiply each digit of 152.25 with its respective positional weight, and last we add
the products of all the bits with its weight.
(152.25)8=(1×82)+(5×81)+(2×80)+(2×8-1)+(5×8-2)
(152.25)8=64+40+2+(2×1⁄8)+(5×1⁄64)
(152.25)8=64+40+2+0.25+0.078125
(152.25)8=106.328125
Example 1: (152.25)8
(152.25)8=(001101010.010101)2
Example 1: (152.25)8
Step 1:
(152.25)8=(001101010.010101)2
Step 2:
1. Now, we make pairs of four bits on both sides of the binary point.
0 0110 1010.0101 01
On the left side of the binary point, the first pair has only one digit, and on the right
side, the last pair has only two-digit. To make them complete pairs of four bits, add
zeros on extreme sides.
Let's take an example to understand how the conversion is done from hexadecimal to
decimal.
Example 1: (152A.25)16
Step 1:
We multiply each digit of 152A.25 with its respective positional weight, and last we
add the products of all the bits with its weight.
(152A.25)16=(1×163)+(5×162)+(2×161)+(A×160)+(2×16-1)+(5×16-2)
(152A.25)16=(1×4096)+(5×256)+(2×16)+(10×1)+(2×16 -1)+(5×16-2)
(152A.25)16=4096+1280+32+10+(2×1⁄16)+(5×1⁄256)
(152A.25)16=5418+0.125+0.125
(152A.25)16=5418.14453125
Example 1: (152A.25)16
For converting hexadecimal to octal, there are two steps required to perform, which are
as follows:
1. In the first step, we will find the binary equivalent of the hexadecimal number.
2. Next, we have to make the pairs of three bits on both sides of the binary point.
If there will be one or two bits left in a pair of three bits pair, we add the
required number of zeros on extreme sides and write the octal digits
corresponding to each pair.
Example 1: (152A.25)16
Step 1:
Step 2:
3. Then, we make pairs of three bits on both sides of the binary point.
(001010100101010.001001010)2=(12452.112)8
Gray Code
The Gray Code is a sequence of binary number systems, which is also known
as reflected binary code. The reason for calling this code as reflected binary code is
the first N/2 values compared with those of the last N/2 values in reverse order. In this
code, two consecutive values are differed by one bit of binary digits. Gray codes are
used in the general sequence of hardware-generated binary numbers. These numbers
cause ambiguities or errors when the transition from one number to its successive is
done. This code simply solves this problem by changing only one bit when the transition
is between numbers is done.
The gray code is a very light weighted code because it doesn't depend on the value of
the digit specified by the position. This code is also called a cyclic variable code as the
transition of one value to its successive value carries a change of one bit only.
2. Next, we find the code for 0, i.e., 0000, which is the same as binary.
3. Now, we take the previous code, i.e., 0000, and change the most significant bit
of it.
4. We perform this process reclusively until all the codes are not uniquely identified.
5. If by changing the most significant bit, we find the same code obtained
previously, then the second most significant bit will be changed, and so on.
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
Excess-3 Code
The excess-3 code is also treated as XS-3 code. The excess-3 code is a non-weighted
and self-complementary BCD code used to represent the decimal numbers. This code
has a biased representation. This code plays an important role in arithmetic operations
because it resolves deficiencies encountered when we use the 8421 BCD code for
adding two decimal digits whose sum is greater than 9. The Excess-3 code uses a
special type of algorithm, which differs from the binary positional number system or
normal non-biased BCD.
We can easily get an excess-3 code of a decimal number by simply adding 3 to each
decimal digit. And then we write the 4-bit binary number for each digit of the decimal
number. We can find the excess-3 code of the given binary number by using the
following steps:
We can also add 0011 in each 4-bit BCD code of the decimal number for getting excess-
3 code.
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
In excess-3 code, the codes 1111 and 0000 are never used for any decimal digit. Let's
take some examples of Excess-3 code.
Digit BCD
3 0011
1 0001
3 0011+0011 0110
1 0001+0011 0100
Digit BCD
8 1000
1 0001
6 0110
1 0001
8 1000+0011 1011
1 0001+0011 0100
6 0110+0011 1001
3) So, the excess-3 code of the decimal number 81.61 is 1011 0100.1001 0100
Self-complementary property
A self-complementary binary code is a code which is always complimented in itself. By
replacing the bit 0 to 1 and 1 to 0 of a number, we find the 1's complement of the
number. The sum of the 1'st complement and the binary number of a decimal is equal
to the binary number of decimal 9.
Note: if we perform the 1's complement of excess-3 of a decimal number, it will be equal to
the excess-3 code of the 9's complement of that decimal number.
For example: If we perform 1's complement of the excess-3 code 1000(decimal 5),
complement value will be 0111, which is the excess-3 code of 9's complement of 5, i.e.,
4(0111).
There are the following advantages of excess-3 code which make it required to use:
4. The codes 0000 and 1111 can cause a fault in the transmission line. The excess-
3 code doesn't use these codes and gives an advantage for memory
organization.
ASCII Code
The ASCII stands for American Standard Code for Information Interchange. The ASCII
code is an alphanumeric code used for data communication in digital computers. The
ASCII is a 7-bit code capable of representing 2 7 or 128 number of different characters.
The ASCII code is made up of a three-bit group, which is followed by a four-bit code.
o The ASCII Code is a 7 or 8-bit alphanumeric code.
o The ASCII code starts from 00h to 7Fh. In this, the code from 00h to 1Fh is used
for control characters, and the code from 20h to 7Fh is used for graphic symbols.
o The 8-bit code holds ASCII, which supports 256 symbols where math and
graphic symbols are added.
o The range of the extended ASCII is 80h to FFh.
Control Characters
The non-printable characters used for sending commands to the PC or printer are
known as control characters. We can set tabs, and line breaks functionality by this
code. The control characters are based on telex technology. Nowadays, it's not so much
popular in use. The character from 0 to 31 and 127 comes under control characters.
Special Characters
All printable characters that are neither numbers nor letters come under the special
characters. These characters contain technical, punctuation, and mathematical
characters with space also. The character from 32 to 47, 58 to 64, 91 to 96, and 123 to
126 comes under this category.
Numbers Characters
This category of ASCII code contains ten Arabic numerals from 0 to 9.
Letters Characters
In this category, two groups of letters are contained, i.e., the group of uppercase
letters and the group of lowercase letters. The range from 65 to 90 and 97 to 122
comes under this category.
ASCII Table
011000 30 48 0 Numbers
0
011000 31 49 1 Numbers
1
011001 32 50 2 Numbers
0
011001 33 51 3 Numbers
1
011010 34 52 4 Numbers
0
011010 35 53 5 Numbers
1
011011 36 54 6 Numbers
0
011011 37 55 7 Numbers
1
011100 38 56 8 Numbers
0
011100 39 57 9 Numbers
1
100000 41 65 A Capital
1 letters
100001 42 66 B Capital
0 letters
100001 43 67 C Capital
1 letters
100010 44 68 D Capital
0 letters
100010 45 69 E Capital
1 letters
100011 46 70 F Capital
0 letters
100011 47 71 G Capital
1 letters
100100 48 72 H Capital
0 letters
100100 49 73 I Capital
1 letters
100101 4A 74 J Capital
0 letters
100101 4B 75 K Capital
1 letters
100110 4C 76 L Capital
0 letters
100110 4D 77 M Capital
1 letters
100111 4E 78 N Capital
0 letters
100111 4F 79 O Capital
1 letters
101000 50 80 P Capital
0 letters
101000 51 81 Q Capital
1 letters
101001 52 82 R Capital
0 letters
101001 53 83 S Capital
1 letters
101010 54 84 T Capital
0 letters
101010 55 85 U Capital
1 letters
101011 56 86 V Capital
0 letters
101011 57 87 W Capital
1 letters
101100 58 88 X Capital
0 letters
101100 59 89 Y Capital
1 letters
101101 5A 90 Z Capital
0 letters
110000 61 97 A Lowercase
1 letters
110001 62 98 B Lowercase
0 letters
110001 63 99 C Lowercase
1 letters
The values are typically represented in ASCII code tables in decimal, binary, and
hexadecimal form.
Example 1:
(100101011000011110110110000110101001110000110111111
01001 110111011101001000000011000101100100110011)2
Step 1: In the first step, we we make the groups of 7-bits because the ASCII code is 7
bit.
Step 2: Then, we find the equivalent decimal number of the binary digits either from
the ASCII table or 64 32 16 8 4 2 1 scheme.
Binary Decimal
64 32 16 8 4 2 1 64+8+2=74
1 0 0 1 0 1 0
64 32 16 8 4 2 1 64+32+1=94
1 1 0 0 0 0 1
64 32 16 8 4 2 1 64+32+16+4+2=118
1 1 1 0 1 1 0
64 32 16 8 4 2 1 64+32+1=97
1 1 0 0 0 0 1
64 32 16 8 4 2 1 64+16+4=84
1 0 1 0 1 0 0
64 32 16 8 4 2 1 64+32+16=112
1 1 1 0 0 0 0
64 32 16 8 4 2 1 64+32+8+4+2+1=111
1 1 0 1 1 1 1
64 32 16 8 4 2 1 64+32+8+1=105
1 1 0 1 0 0 1
64 32 16 8 4 2 1 64+32+8+4+2=110
1 1 0 1 1 1 0
64 32 16 8 4 2 1 64+32+16+4=116
1 1 1 0 1 0 0
64 32 16 8 4 2 1 64
1 0 0 0 0 0 0
64 32 16 8 4 2 1 32+16+1=49
0 1 1 0 0 0 1
64 32 16 8 4 2 1 32+16+2=50
0 1 1 0 0 1 0
64 32 16 8 4 2 1 32+16+2+1=51
0 1 1 0 0 1 1
Step 3: Last, we find the equivalent symbol of the decimal number from the ASCII
table.
Decimal Symbol
74 J
94 a
118 v
97 a
84 T
112 p
111 o
105 i
110 n
116 t
64 @
49 1
50 2
51 3
It is very easy to represent positive and negative numbers in our day to day life. We
represent the positive numbers without adding any sign before them and the negative
number with - (minus) sign before them. But in the digital system, it is not possible to
use negative sign before them because the data is in binary form in digital computers.
For representing the sign in binary numbers, we require a special notation.
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. Because of one unique binary equivalent form
of a number in unsigned number representation, it is known as unambiguous
representation technique. The range of the unsigned binary numbers starts from 0 to
(2n-1).
We will change this decimal number into binary, which has the only magnitude of the
given name.
102 102/2 51 0
51 51/2 25 1
25 25/2 12 1
12 12/2 6 0
6 6/2 3 0
3 3/2 1 1
1 1/2 0 1
Signed Numbers
The signed numbers have a sign bit so that it can differentiate positive and negative
integer numbers. 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 numbers are represented in three ways. The signed bit makes two possible
representations of zero (positive (0) and negative (1)), which is an ambiguous
representation. The third representation is 2's complement representation in which no
double representation of zero is possible, which makes it unambiguous representation.
There are the following types of representation of signed binary numbers:
1. Sign-Magnitude form
In this form, a binary number has a bit for a sign symbol. If this bit is set to 1,
the number will be negative else the number will be positive if it is set to 0.
Apart from this sign-bit, the n-1 bits represent the magnitude of the number.
2. 1's Complement
By inverting each bit of a number, we can obtain the 1's complement of a
number. The negative numbers can be represented in the form of 1's
complement. In this form, the binary number also has an extra bit for sign
representation as a sign-magnitude form.
3. 2's Complement
By inverting each bit of a number and adding plus 1 to its least significant bit, we
can obtain the 2's complement of a number. The negative numbers can also be
represented in the form of 2's complement. In this form, the binary number also
has an extra bit for sign representation as a sign-magnitude form.
1's complement
In number representation techniques, the binary number system is the most used
representation technique in digital electronics. The complement is used for representing
the negative decimal number in binary form. Different types of complement are
possible of the binary number, but 1's and 2's complements are mostly used for binary
numbers. We can find the 1's complement of the binary number by simply inverting the
given number. For example, 1's complement of binary number 1011001 is 0100110.
We can find the 2's complement of the binary number by changing each bit(0 to 1 and
1 to 0) and adding 1 to the least significant bit. For example, 2's complement of binary
number 1011001 is (0100110)+1=0100111.
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.
Example 1: 11010.1101
For finding 1's complement of the given number, change all 0's to 1 and all 1's to 0. So
the 1's complement of the number 11010.1101 comes out 00101.0010.
Example 2: 100110.1001
For finding 1's complement of the given number, change all 0's to 1 and all 1's to 0. So,
the 1's complement of the number 100110.1001 comes out 011001.0110.
0000 1111
0001 1110
0010 1101
0011 1100
0100 1011
0101 1010
0110 1001
0111 1000
1000 0111
1001 0110
1010 0101
1011 0100
1100 0011
1101 0010
1110 0001
1111 0000
Let's take an example of a positive and negative number and see how these numbers
are represented.
Example 1: +6 and -6
The number +6 is represented as same as the binary number. For representing both
numbers, we will take the 5-bit register.
1. +6=0 0110
2. Find the 1's complement of the number 0 0110, i.e., 1 1001. Here, MSB denotes
that a number is a negative number.
Here, MSB refers to Most Significant Bit, and LSB denotes the Least Significant Bit.
The number +120 is represented as same as the binary number. For representing both
numbers, take the 8-bit register.
2. Now, find the 1's complement of the number 0 1111000, i.e., 1 0000111. Here,
the MSB denotes the number is the negative number.
2's complement
Just like 1's complement, 2's complement is also used to represent the signed binary
numbers. For finding 2's complement of the binary number, we will first find the 1's
complement of the binary number and then add 1 to the least significant bit of it.
For example, if we want to calculate the 2's complement of the number 1011001, then
firstly, we find the 1's complement of the number that is 0100110 and add 1 to the
LSB. So, by adding 1 to the LSB, the number will be (0100110)+1=0100111. We can
also create the logic circuit using OR, AND, and NOT gates. The logic circuit for finding
2's complement of the 5-bit binary number is as follows:
Example 1: 110100
For finding 2's complement of the given number, change all 0's to 1 and all 1's to 0. So
the 1's complement of the number 110100 is 001011. Now add 1 to the LSB of this
number, i.e., (001011)+1=001100.
Example 2: 100110
For finding 1's complement of the given number, change all 0's to 1 and all 1's to 0. So,
the 1's complement of the number 100110 is 011001. Now add one the LSB of this
number, i.e., (011001)+1=011010.
The number +6 is represented as same as the binary number. For representing both
numbers, take the 5-bit register.
1. +6=0 0110
2. Now, find the 1's complement of the number 0 0110, i.e. 1 1001.
3. Now, add 1 to its LSB. When we add 1 to the LSB of 11001, the newly generated
number comes out 11010. Here, the sign bit is one which means the number is
the negative number.
The number +120 is represented as same as the binary number. For representing both
numbers, take the 8-bit register.
1. +120=0 1111000
2. Now, find the 1's complement of the number 0 1111000, i.e. 1 0000111. Here,
the MSB denotes the number is the negative number.
3. Now, add 1 to its LSB. When we add 1 to the LSB of 1 0000111, the newly
generated number comes out 1 0001000. Here, the sign bit is one, which means
the number is the negative number.
9's Complement
The 9's complement is used to find the subtraction of the decimal numbers. The 9's
complement of a number is calculated by subtracting each digit of the number by 9.
For example, suppose we have a number 1423, and we want to find the 9's
complement of the number. For this, we subtract each digit of the number 1423 by
9. So, the 9's complement of the number 1423 is 9999-1423= 8576.
With the help of the 9's complement, the process of subtraction is done in a much
easier way. Generally, we subtract the subtrahend from the minuend, but in a case
when we perform subtraction using 9's complement, there is no need to do the
same.
For subtracting two numbers using 9's complement, we first have to find the 9's
complement of the subtrahend and then we will add this complement value with the
minuend. There are two possible cases when we subtract the numbers using 9's
complement.
For subtracting the smaller number from the larger number using 9's complement,
we will find the 9's complement of the subtrahend, and then we will add this
complement value with the minuend. By adding both these values, the result will
come in the formation of carry. At last, we will add this carry to the result obtained
previously.
In this case, when we add the complement value and the minuend, the result will
not come in the formation of carry. This indicates that the number is negative, and
for finding the final result, we need to find the 9's complement of the result.
10's Complement
The 10's complement is also used to find the subtraction of the decimal numbers.
The 10's complement of a number is calculated by subtracting each digit by 9 and
then adding 1 to the result. Simply, by adding 1 to its 9's complement we can get its
10's complement value. For example, suppose we have a number 1423, and we
want to find the 10's complement of the number. For this, we find the 9's
complement of the number 1423 that is 9999-1423= 8576, and now we will add 1 to
the result. So the 10's complement of the number 1423 is 8576+1=8577.
For subtracting two numbers using 10's complement, we first have to find the 10's
complement of the subtrahend, and then we will add this complement value with the
minuend. There are two possible cases when we subtract the numbers using 10's
complement.
For subtracting the smaller number from the larger number using 10's complement,
we will find the 10's complement of the subtrahend and then we will add this
complement value with the minuend. By adding both these values, the result will
come in the formation of carry. We ignore this carry and the remaining digits will be
the answer.
In this case, when we add the complement value and the minuend, the result will
not come in the formation of carry. This indicates that the number is negative and
for finding the final result, we need to find the 10's complement of the result
obtained by adding complement value of subtrahend and minuend.
If the base of the number is 2, then we can find 1's and 2's complement of the number.
Similarly, if the number is the octal number, then we can find 7's and 8's complement
of the number.
There is the following formula for finding the r's and (r-1)'s complement:
r' s= complement=(rn )10-N
(r-1)' s complement={(rn)10-1}-N
o In r's complement, we can further use existing addition circuitry means there is
no special circuitry.
o There is no need to determine whether the minuend and subtrahend are larger
or not because the result has the right sign automatically.
o The negative zeros are eliminated by r's complement.
Let's take some examples to understand how we can calculate the r's and (r-1)'s
complement of binary, decimal, octal, and hexadecimal numbers.
Example 1: (1011000)2
This number has a base of 2, which means it is a binary number. So, for the binary
numbers, the value of r is 2, and r-1 is 2-1=1. So, we can calculate the 1's and 2's
complement of the number.
={(27 )10-1}-(1011000)2
={(128)10-1}-(1011000)2
={(127)10}-(1011000)2
=11111112-10110002
=0100111
=(27 )10-(1011000)2
=(128)10-(1011000)2
=100000002-10110002
=01010002
Example 2: (155)10
This number has a base of 10, which means it is a decimal number. So, for the decimal
numbers, the value of r is 10, and r-1 is 10-1=9. So, we can calculate the 10's and 9's
complement of the number.
={(103 )10-1}-(155)10
=(1000-1)-155
=999-155
=(844)10
10's complement of the number 1011000 is calculated as:
=(103 )10-(15510
=1000-155
=(845)10
Example 3: (172)8
This number has a base of 8, which means it is an octal number. So, for the octal
numbers, the value of r is 8, and r-1 is 8-1=7. So, we can calculate the 8's and 7's
complement of the number.
={(83 )10-1}-(172)8
=((512)10-1)-(132)8
=(511)10-(122)10
=(389)10
=(605)8
=(83 )10-(172)8
=(512)10-1728
=51210-12210
=39010
=6068
Example 4: (F9)16
This number has a base of 16, which means it is a hexadecimal number. So, for the
hexadecimal numbers, the value of r is 16, and r-1 is 16-1=15. So, we can calculate
the 16's and 15's complement of the number.
{(162 )10-1}-(F9)16
(256-1)10-F916
25510-24910
(6)10
(6)16
{(162 )10 }-(F9)16
25610-24910
(7)10
(7)16
Addition and Subtraction using 1's complement
In our previous section, we learned about different complements such as 1's
complement, 2's complement, 9's complement, and 10's complement, etc.. In this
section, we will learn to perform the arithmetic operations such as addition and
subtraction using 1's complement. We can perform addition and subtraction using 1's,
2's, 9's, and 10's complement.
Case 1: Addition of the positive number with a negative number when the
positive number has a greater magnitude.
Initially, calculate the 1's complement of the given negative number. Sum up with the
given positive number. If we get the end-around carry 1, it gets added to the LSB.
1. First, find the 1's complement of the negative number 1001. So, for finding 1's
complement, change all 0 to 1 and all 1 to 0. The 1's complement of the number
1001 is 0110.
3. By adding both numbers, we get the end-around carry 1. We add this end
around carry to the LSB of 0011.
0011+1=0100
Case 2: Adding a positive value with a negative value in case the negative
number has a higher magnitude.
Initially, calculate the 1's complement of the negative value. Sum it with a positive
number. In this case, we did not get the end-around carry. So, take the 1's
complement of the result to get the final result.
3. Now, find the 1's complement of the result 1110 that is the final result. So, the
1's complement of the result 1110 is 0001, and we add a negative sign before
the number so that we can identify that it is a negative number.
In this case, first find the 1's complement of both the negative numbers, and then we
add both these complement numbers. In this case, we always get the end-around
carry, which get added to the LSB, and for getting the final result, we take the 1's
complement of the result.
1. Firstly find the 1's complement of the negative numbers 01101 and 01110. So,
for finding 1's complement, we change all 0 to 1, and all 1 to 0. 1's complement
of the number 01110 is 10001, and 01101 is 10010.
2. Now, we add both the complement numbers, i.e., 10001 and 10010;
10001+10010= 1 00011
3. By adding both numbers, we get the end-around carry 1. We add this end-
around carry to the LSB of 00011.
00011+1=00100
4. Now, find the 1's complement of the result 00100 that is the final answer. So,
the 1's complement of the result 00100 is 110111, and add a negative sign
before the number so that we can identify that it is a negative number.
o If got a carry, add the carry to its LSB. Else take 1's complement of the result
which will be negative
We take 1's complement of subtrahend 00111, which comes out 11000. Now, sum
them. So,
10101+11000 =1 01101.
In the above result, we get the carry bit 1, so add this to the LSB of a given result, i.e.,
01101+1=01110, which is the answer.
We take 1's complement of subtrahend 10111, which comes out 01000. Now, add both
of the numbers. So,
10101+01000 =11101.
In the above result, we didn't get the carry bit. So calculate the 1's complement of the
result, i.e., 00010, which is the negative number and the final answer.
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.
3. By adding both numbers, we get the end-around carry 1. We discard the end-
around carry. So, the addition of both numbers is 0100.
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.
1. First, find the 2's complement of the negative number 1110. So, for finding 2's
complement, add 1 to the LSB of its 1's complement value 0001.
0001+1=0010
3. Find the 2's complement of the result 1110 that is the final result. So, the 2's
complement of the result 1110 is 0001, and add a negative sign before the
number so that we can identify that it is a negative number.
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.
3. By adding both numbers, we get the end-around carry 1. This carry is discarded
and the final result is the 2.s complement of the result 00101. So, the 2's
complement of the result 00101 is 11011, and we add a negative sign before the
number so that we can identify that it is a negative number.
o If we get the carry by adding both the numbers, then we discard this carry and
the result is positive else take 2's complement of the result which will be
negative.
We take 2's complement of subtrahend 00111, which is 11001. Now, sum them. So,
10101+11001 =1 01110.
In the above result, we get the carry bit 1. So we discard this carry bit and remaining is
the final result and a positive number.
We take 2's complement of subtrahend 10111, which comes out 01001. Now, we add
both of the numbers. So,
10101+01001 =11110.
In the above result, we didn't get the carry bit. So calculate the 2's complement of the
result, i.e., 00010. It is the negative number and the final answer.
Fixed Point and Floating Point Number
Representations
Data Structure and AlgorithmsMathematicsDigital Electronics
Digital Computers use Binary number system to represent all types of information inside
the computers. Alphanumeric characters are represented using binary bits (i.e., 0 and
1). Digital representations are easier to design, storage is easy, accuracy and precision
are greater.
There are various types of number representation techniques for digital number
representation, for example: Binary number system, octal number system, decimal
number system, and hexadecimal number system etc. But Binary number system is
most relevant and popular for representing numbers in digital computer system.
There are two major approaches to store real numbers (i.e., numbers with fractional
component) in modern computing. These are (i) Fixed Point Notation and (ii) Floating
Point Notation. In fixed point notation, there are a fixed number of digits after the
decimal point, whereas floating point number allows for a varying number of digits after
the decimal point.
Fixed-Point Representation −
This representation has fixed number of bits for integer part and for fractional part. For
example, if given fixed-point representation is IIII.FFFF, then you can store minimum
value is 0000.0001 and maximum value is 9999.9999. There are three parts of a fixed-
point number representation: the sign field, integer field, and fractional field.
So, actual number is (-1)s(1+m)x2(e-Bias), where s is the sign bit, m is the mantissa, e is the
exponent value, and Bias is the bias number.
Note that signed integers and exponent are represented by either sign representation,
or one’s complement representation, or two’s complement representation.
The floating point representation is more flexible. Any non-zero number can be
represented in the normalized form of ±(1.b1b2b3 ...)2x2n This is normalized form of a
number x.
Example −Suppose number is using 32-bit format: the 1 bit sign bit, 8 bits for signed
exponent, and 23 bits for the fractional part. The leading bit 1 is not stored (as it is
always 1 for a normalized number) and is referred to as a “hidden bit”.
Then −53.5 is normalized as -53.5=(-110101.1)2=(-1.101011)x25 , which is represented
as following below,
Where 00000101 is the 8-bit binary value of exponent value +5.
Note that 8-bit exponent field is used to store integer exponents -126 ≤ n ≤ 127.
The smallest normalized positive number that fits into 32 bits is
(1.00000000000000000000000)2x2-126=2-126≈1.18x10-38 , and largest normalized positive
number that fits into 32 bits is (1.11111111111111111111111) 2x2127=(224-1)x2104 ≈
3.40x1038 . These numbers are represented as following below,
The precision of a floating-point format is the number of positions reserved for binary
digits plus one (for the hidden bit). In the examples considered here the precision is
23+1=24.
The gap between 1 and the next normalized floating-point number is known as machine
epsilon. the gap is (1+2-23)-1=2-23for above example, but this is same as the smallest
positive floating-point number because of non-uniform spacing unlike in the fixed-point
scenario.
Note that non-terminating binary numbers can be represented in floating point
representation, e.g., 1/3 = (0.010101 ...) 2 cannot be a floating-point number as its binary
representation is non-terminating.
IEEE Floating point Number Representation −
IEEE (Institute of Electrical and Electronics Engineers) has standardized Floating-Point
Representation as following diagram.
So, actual number is (-1)s(1+m)x2(e-Bias), where s is the sign bit, m is the mantissa, e is the
exponent value, and Bias is the bias number. The sign bit is 0 for positive number and 1
for negative number. Exponents are represented by or two’s complement
representation.
According to IEEE 754 standard, the floating-point number is represented in following
ways:
Half Precision (16 bit): 1 sign bit, 5 bit exponent, and 10 bit mantissa
Single Precision (32 bit): 1 sign bit, 8 bit exponent, and 23 bit mantissa
Double Precision (64 bit): 1 sign bit, 11 bit exponent, and 52 bit mantissa
Quadruple Precision (128 bit): 1 sign bit, 15 bit exponent, and 112 bit mantissa
Special Value Representation −
There are some special values depended upon different values of the exponent and
mantissa in the IEEE 754 standard.
All the exponent bits 0 with all mantissa bits 0 represents 0. If sign bit is 0, then
+0, else -0.
All the exponent bits 1 with all mantissa bits 0 represents infinity. If sign bit is 0,
then +∞, else -∞.
All the exponent bits 0 and mantissa bits non-zero represents denormalized
number.
All the exponent bits 1 and mantissa bits non-zero represents error.