As can be seen, there is nBit argument which decides the output bit-width.
e.g. let dwnum=4095, when nBit=16, the result is "0FFF", when nBit=32, the result is "00000FFF", when the nBit=0, the result="FFF"



Long2Hex proc uses ebx edi edx dwnum:DWORD,lpBuf:DWORD,nBit:DWORD
mov edi,lpBuf
mov ebx,dwnum
mov ecx,nBit
mov edx,1
.if ecx==0
mov ecx,8
xor edx,edx
.elseif ecx<32
ror ebx,cl
shr ecx,2 ; ecx=ecx/4
.else
mov ecx,8
.endif

mloop:
rol ebx,4
mov al,bl
and al,0FH
.if edx==0
.if al==0
loop mloop
mov ecx,1
.endif
mov edx,1
.endif
or al,30H
.if al>39H
add al,7
.endif
mov [edi],al
inc edi
loop mloop

mov byte ptr [edi],0
ret
Long2Hex endp
Posted on 2003-11-26 06:07:42 by optimus
Could you specify what is it coded for? Speed or size? Somehow I do not think it is optimised.
Posted on 2003-11-26 09:10:46 by roticv



DwToHex proc ; lpBuffer,source

xchg eax,esi

pop edx ; EIP
pop ecx ; dValue
pop esi ; lpBupp
push edx ; EIP

xor edx,edx
mov dl,8
dec esi

push eax
@@:
mov eax,ecx
and al,0fh
cmp al,10
jl short DTW_num
sub al,10
add al,41h
jmp short DTW_Keep_go
DTW_num:
add al,30h
DTW_Keep_go:
mov [esi+edx],al
shr ecx,4
dec edx
jnz @b
pop esi
mov byte ptr [esi+8],0
ret

dwTohex endp



dwToHex did not need any base. It fixed to 16-Bit. The char only 0~1 and 'A'~'F'.:tongue:.
Posted on 2003-12-03 08:20:53 by realvampire
realvampire, where do you see a base in the original routine?
Posted on 2003-12-03 09:12:52 by gliptic
but i do need for my app



dwToHex did not need any base. It fixed to 16-Bit. The char only 0~1 and 'A'~'F'.:tongue:.
Posted on 2003-12-03 22:28:41 by optimus

realvampire, where do you see a base in the original routine?



MikroData Magazine. The original routine is from HLL language (Delphi).
Posted on 2003-12-05 16:06:07 by realvampire