Asked By
cedar17777
0 points
N/A
Posted on - 07/22/2011
Hi!
I have a question relevant to the ASSEMBLY language. I consider myself weak in converting values from one form to another. Â I want to know the method of converting the DECIMAL values into BINARY and HEXADECIMAL and BINARY into DECIMAL and HEXADECIMAL.
Can anybody help me through this?
Converting values from one form into another
Conversion of Decimal to binary is a matter of doing division by 2 and taking into account the remainder.
Example: find the Binary of 12010
Notes |
Division |
Result |
Remainder |
Start by dividing the number by 2Â (120/2). |
120/2 |
60 |
0 |
Using the result, divide it by 2 again |
60/2 |
30 |
0 |
Keep repeating the above step until you get 0 for result |
30/2 |
15 |
0 |
 |
15/2 |
7
|
1 |
 |
7/2 |
3 |
1 |
 |
3/2 |
1 |
1 |
To get the binary equivalent, read the remainder from bottom to top |
1/2 |
0 |
1 |
Binary of 12010 is 111 10002
Apply the same logic for Hexademcial but use 16 instead of 2
Notes |
Division |
Result |
Remainder |
Start by dividing the number by 16 (120/16). |
120/16 |
7 |
8 |
Using the result, divide it by 16 again |
7/16 |
0 |
7 |
Keep repeating the above step until you get 0 for result |
 |
 |
 |
Again, read the reminder from the bottom to get the resultant conversion.
Hexadecimal of 12010 is 7816
To convert from binary to decimal, you would have to do the following:
Example: Find the decimal of 111 10002
1 x 26 + 1 x 25 + 1 x 24 + 1 x 23 + 0 x 22 +Â 0 x 21 +Â 0 x 20 = 12010
Notice that the power is the position of the number itself.
Conversion of binary to Hexadecimal is slightly more complex.
Example: Find the Hexadecimal of 111 10002
Step 1: Group the numbers into groups of four. Â If there is a shortfall, pad some '0' in the front of the series.
a0111 10002
Step 2: Convert each group into their decimal equivalent. Â Remember to change 10 to A, 11 to B and so on.
7 8
Step 3: Simply combine the numbers together to get the hexadecimal conversion.
7816
Answered By
Nadya
0 points
N/A
#86020
Converting values from one form into another
Hello,
To convert DECIMAL to BINARY (positional notation with radix of 2 (q=2)) we should divide decimal number by 2 while integer part > 0 .
As a result in binary system we will have sorted sequence reminders, which have got from the deletion in inverse order (the first digit of number is the last reminder, the last digit – the first reminder ).
Example:
Convert decimal 29 to binary.
29 : 2 = 14( reminder 1).
14 : 2 = 7Â ( reminder 0).
7 : 2 = 3Â Â Â (reminder 1).
3 : 2 = 1Â Â Â (reminder 1).
1 : 2 = 0Â Â Â (reminder 1).
Don’t forget to take reminders in the inversed order!
Â
We got 29 in decimal equal 11101 in binary.
In Assembly we write with descriptor: D – decimal, B – binary.
29d -> 11101b. Â Â Â Â Â Â
To convert number from BINARY to DECIMAL you have to take the digit from the number and add the sum of your previous result multiplied to 2 (the first sum = 0 ). And do it for all digits one by one. The last sum will be your result.
Example:
convert 11101b to d.
1 +Â 0*2 = 1.
1 +Â 1*2 = 3.
1 +Â 3*2 = 7.
0 +Â 7*2 = 14.
1 + 14*2 = 29.
We got 11101b -> 29d.
To work with HEXADECIMAL system you can use the table:
Table 1.
bin    hex   dec
0000Â Â Â 0Â Â Â Â 0
0001Â Â Â 1 Â Â Â 1
0010Â Â Â 2Â Â Â Â 2
0011Â Â Â 3Â Â Â Â 3
0100Â Â Â 4Â Â Â Â 4
0101Â Â Â 5Â Â Â Â 5
0110Â Â Â 6Â Â Â Â 6
0111Â Â Â 7Â Â Â Â 7
1000Â Â Â 8Â Â Â Â 8
1001Â Â Â 9Â Â Â Â 9
1010Â Â Â AÂ Â Â 10
1011Â Â Â BÂ Â Â 11
1100Â Â Â CÂ Â Â 12
1101Â Â Â DÂ Â Â 13
1110Â Â Â E Â Â Â 14
1111Â Â Â FÂ Â Â 15
Convert DECIMAL to HEXADECIMAL.
To convert decimal to hexadecimal you can use the same logic as for conversion decimal to binary: but divide number by 16.
Example:
300 : 16 = 18 ( reminder 12d -> Ch ).
18Â : 16 = 1Â ( reminder 2 ).
1Â Â : 16 = 0Â ( reminder 1 ).
300d = 2Ch.
To simplify deletion, you can either convert decimal number to binary at first and binary to hexadecimal at second.
Example:
300 : 2 = 150 ( reminder 0 ).
150 : 2 = 75Â ( reminder 0 ).
75Â : 2 = 37Â ( reminder 1 ).
37Â : 2 = 18Â ( reminder 1 ).
18Â : 2 = 9Â Â ( reminder 0 ).
9Â Â : 2 = 4Â Â ( reminder 1 ).
4Â Â : 2 = 2Â Â ( reminder 0 ).
2Â Â : 2 = 1Â Â ( reminder 0 ).
1Â Â : 2 = 0Â Â ( reminder 1 ).
we got: 001011001b -> 0010.1100.1000b -> 2ch.
To convert BINARY to HEXADECIMAL just use the table 1.
100101101011b = 1001.0110.1011b = 96B