How to convert hexadecimal number from binary number assembly 8086? I need to convert from a binary number - hexadecimaly number/
-
Related: [How to convert a binary integer number to a hex string?](https://stackoverflow.com/q/53823756) – Peter Cordes Mar 29 '20 at 05:34
1 Answers
I will give you a hand with the algorithm (I would give you the code too, but I don't want you to miss the joy of programming) : you start by capturing the binary number as string (using int 21h, ah=0Ah), then you take the characters from right to left in groups of 4 (for example, using register SI as a pointer and CX as a counter), each group is one hex digit, this digit you store it in another string (also, from right to left, use DI register for this second string), example:
10 1010 1011 0111 ◄ BINARY
2 A B 7 ◄ HEX
Remember bits count from right to left, so each group will requiere one procedure to convert it from binary to hex, this is how to give a value to each binary character in powers of 2 :
1011
│││└─ 2^0 = 1 ─┐
││└── 2^1 = 2 │ 1+2+8 = 11 (B hex digit)
│└─── 2^2 = 4 │ Notice 4 is ignored because its bin character is zero.
└──── 2^3 = 8 ─┘
You don't need a procedure to get powers of 2 because you only have groups of 4 characters, just walk over each character and, if it is "1" add the proper value (1, 2, 4, 8), if it is zero ignore it.
Notice the last group might be odd, once you make it work for even groups you handle the last odd group.

- 10,206
- 3
- 31
- 38
-
@RomDitkovsky, try to implement this answer, if you get stuck in some point, come back, update your question **with your code** and we will help you to fix it. – Jose Manuel Abarca Rodríguez Oct 04 '16 at 17:58