Conversion of one number system to another
We can use following formula:
where,
N is the number with Radix r
n is the total number of digits in number N
di is the value of digit at position i
Let"s try with converting Decimal to Decimal :) :
Here,
N = 2024
r = 10
d0 = 4
d1 = 2
d2 = 0
d3 = 2
So,
Trying with binary,
Here,
N = 1101
r = 2
d0 = 1
d1 = 0
d2 = 1
d3 = 1
So,
For binary, another way to convert is to add the value of 2 to the power of the position where the value is 1.
1 | 1 | 0 | 1 |
---|---|---|---|
d3 | d2 | d1 | d0 |
23 | 22 | - | 20 |
8 | 4 | - | 1 |
adding all of them gives us 13. We ignored d1 because the value at that position is 0
.
Let"s try with converting Hexadecimal to Decimal :
Here,
N = 6D1A
r = 16
d0 = A
d1 = 1
d2 = D
d3 = 6
So,
Converting A and D to their decimal equivalent:
Example, converting 19153 to Hexadecimal:
Number | Division | Quotient | Remainder |
---|---|---|---|
19153 | , r=1 | 1197 | 1 |
1197 | , r=13 | 74 | 13 |
74 | , r=10 | 4 | 10 |
4 | , r=4 | 0 | 4 |
Stopped as r < R, remainder is less than radix
Writing the remainders from bottom to top, from last to first:
4 : 10 : 13 : 1
= 4AD1base 16
Simply convert the individual digits to their binary equivalent, also add extra 0
s so that the binary equivalent number becomes 4 digit one.
4 | A | D | 1 |
---|---|---|---|
0 100 |
1010 | 1101 | 000 1 |
and combining them, we get
(4AD1)16 = (0100101011010001)2
We can remove the first zero, so it becomes (100101011010001)2
If we want to convert binary to hexadecimal, do the reverse, but first break the binary number to group of 4 digits starting from the least significant bit, add the number of 0
s in the group where the number of digits in less than 4 to complete it, and then write the binary equivalent to it.
Taking the above example, to convert (100101011010001)2 to hexadecimal:
0 100 |
1010 | 1101 | 0001 |
---|---|---|---|
4 | A | D | 1 |
and combining them, we get
(0100101011010001)2 = (4AD1)16
Here, we broke the bits into groups of 4 from the least significant bit(right to left), and added a 0
to make 100 4-digit one, 0100, and then converted those groups to hexadecimal.
© progshala.in