hi i've this question for you all, i've stored in eax a decimal number , how can i convert it to hex? tnx
Posted on 2001-01-14 11:43:00 by truBner
Following text came from an *partly* backup of the old beseen board, unfortunately I don't have the names of the guys who wrote it: Number 1: .DATA szDec db "%d", 0 ;For getting the "Ord"-Value szHex db "%x", 0 ;For getting the "Hex"-Value szTheResult db 100 dup(?) ;Here comes the result theCharToConvert db 'D' .CODE ;For getting the "Ord"-Value you would call: invoke wsprintfA, offset szTheResult, offset szDec, theCharToConvert ;For getting the "Hex"-Value you would call: invoke wsprintfA, offset szTheResult, offset szHex, theCharToConvert ;Then are you having the readable result as a string in szTheResult Number 2: For doing a Decimal to hex conversation is quite simple-> .DATA hexchars db '0123456789ABCDEF' .CODE dec2hex proc dec : BYTE, wheretosave:PTR BYTE mov ebx, wheretosave movzx eax, dec and eax, 01111b ;Use the lower 4 nibbles mov eax, hexchars ;Get the character mov , al movzx eax, dec shr eax, 4 ;Use the higher 4 nibbles mov eax, hexchars ;Get the character mov , al ret dec2hex endp [...] .DATA string db 'The Hex is: ' hex db ' ', 0 .CODE [...] invoke dec2hex, 0A5H, offset hex
Posted on 2001-01-14 13:22:00 by JimmyClif
Yet another way of conversion I write and I'm using. ;*/ ========================================================= ;*/ Call with ;*/ lea esi,ASCII_decimal ;*/ call ASCIItoHex ASCIItoHex: ;*/ Convert dedimal ASCII to HEX number xor ebx,ebx ;*/ esi point to decimal number in memory xor edx,edx ASCII_to_HEX: xor eax,eax lodsb sub al,30h ;*/ Convert ASCII to BCD number jl @f cmp al,9 ;*/ Is it in the range ? jg @f xchg eax,ebx ;*/ Convert it to HEX push ecx ;*/ one by one until mov ecx,10 ;*/ valid numbers mul ecx ;*/ Result is finaly pop ecx ;*/ in EBX xchg eax,ebx ;*/ add ebx,eax ;*/ mov edx,1 jmp ASCII_to_HEX @@: retn ;*/ result HEX Number is in ebx ;*/Maximum number is 4,294,967,295 decimal as ASCII = ;*/number db 34,32,39,34,39,36,37,32,39,35,00 or "4294967295",0 ;*/ ========================================================= John
Posted on 2001-01-14 17:57:00 by john