Hex to Decimal Conversion
To convert from Hex to Decimal, multiply the value in each position by its hex weight and add each value.
Example: 0AFB2H (we would expect to obtain the decimal value 44978)
A*163 | F*162 | B*161 | 2*160 |
10*4096 | 15*256 | 11*16 | 2*1 |
40960 | 3840 | 176 | 2 |
40960 + 3840 + 176 + 2 = 44978
Decimal to Hex Conversion
To convert decimal to hex is slightly more difficult. The typical method to convert from decimal to hex is repeated division by 16.
To convert decimal to hex is slightly more difficult. The typical method to convert from decimal to hex is repeated division by 16.
For this method, divide the decimal number by 16, and write the remainder on the side as the least significant digit. This process is continued by dividing the quotient by 16 and writing the remainder until the quotient is 0. When performing the division, the remainders which will represent the hex equivalent of the decimal number are written beginning at the least significant digit (right) and each new digit is written to the next more significant digit (the left) of the previous digit.
Consider the number 44978.
Division | Quotient | Remainder | Hex Number |
44978 / 16 | 2811 | 2 | 2 |
2811 / 16 | 175 | 11 | B2 |
175 / 16 | 10 | 15 | FB2 |
10 / 16 | 0 | 10 | 0AFB2 |
As you can see, we are back with the original number. That is what we should expect.
When you use hex numbers in an 8085 program, the Assembler usually requires the most significant hex digit to be 0 even if this number of digits exceed the size of the register. This is an Assembler requirement and your value will be assembled correctly.