Converting values from one form into another

Asked By 0 points N/A Posted on -
qa-featured

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?

SHARE
Best Answer by WsaENoTsoCK
Best Answer
Best Answer
Answered By 5 points N/A #86019

Converting values from one form into another

qa-featured

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 0 points N/A #86020

Converting values from one form into another

qa-featured

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

Related Questions