# Converting Decimal numbers to Hex

I just don't get it!! I've read so much about converting numbers and all I understand is how to convert Hex to Decimal, but I want to convert a Decimal number to Hex, can anyone explain how to? Examples would be great too.

Thanks,
Navic

• Multiply your destination by 10, add a decimal digit (if it's ASCII, subtract 30h from it first), and repeat until you're done.
• : Multiply your destination by 10, add a decimal digit (if it's ASCII, subtract 30h from it first), and repeat until you're done.
:

What do you mean destination? If I had the decimal number 933, how would I get the hex value of 3A5h?
• In this example I will use the 32-bit version of MUL:
[code]DecASCII2Hex PROC
mov si,offset ASCIInum
xor ecx,ecx
xor eax,eax
xor edx,edx
mov ebp,10 ;The source base is decimal.

Dec2HexLoop:
mov cl,[si]
test cl,cl ;Check to see if this byte is zero.
jz OutOfHere
mul ebp ;EDX:EAX = EAX * EBP
jc OverFlow ;Check for an unsigned overflow.
sub cl,30h ;Convert the ASCII digit to BCD.
inc si ;Increment the pointer.
jnc Dec2HexLoop
OverFlow: ;CF is already set if here.
OutOfHere: ;CF is already clear here.
;At this point, EAX should be equal to 3A5h.
ret
DecASCII2Hex ENDP

ASCIInum db "933",0 ;Most decimal numbers come in in ASCII form.[/code]

In the example, the destination was EAX (I also called it the total).