News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

hex/dec to bin

Started by azdps, May 26, 2008, 09:35:55 PM

Previous topic - Next topic

azdps

im opening a registry key to get a hex or dec value (dword). im able to obtain the value but i need the value returned to be in bin format so that i can check for which bits are set or not set. once i obtain my dword value how would i do that?

NightWare

if you have obtained the dword, then IT'S in bin/hex/dec...  :toothy coz bin/hex/dec are just views of the value.

if you want to test the bits, use "bt reg,bit" (where here the bit go from 0 to 31)
and if the bit is positionned the carry flag = 1, otherwise = 0. and then, you just have to jump with "jc" or "jnc" where you want...

if you want to convert the value in binary string, you can use :
ALIGN 16
;
; convert a dword to binary string
;
; Syntax :
; mov eax,Dword
; mov esi,String (33 bytes, 32 digit+final zero)
; call Dw2Bin
;
; Return :
; nothing
;
Dw2Bin PROC
; push eax
; push edx
push esi
push edi

test eax,eax
jz Label05
mov edi,esi
Label01: shr eax,1
setc dl
add dl,"0"
mov BYTE PTR [edi],dl
inc edi
test eax,eax
jnz Label01
mov BYTE PTR [edi],0
Label02: dec edi
mov dl,BYTE PTR [esi]
mov dh,BYTE PTR [edi]
mov BYTE PTR [edi],dl
mov BYTE PTR [esi],dh
inc esi
cmp esi,edi
jb Label02
Label03:
pop edi
pop esi
; pop edx
; pop eax
ret

Label05: mov WORD PTR [esi],30h

pop edi
pop esi
; pop edx
; pop eax
ret
Dw2Bin ENDP


herge

 Hi  azdps:


; DW2B.ASM 6:56 AM 5/27/2008
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .code
start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL Pbuf  :DWORD
    LOCAL buff[65]:BYTE

    mov Pbuf, ptr$(buff)

    mov eax, 2147483647         ; decimal number input

    invoke dw2bin_ex,eax,Pbuf   ; change it to ascii binary

    print Pbuf,13,10            ; print result to console

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start



Try this.

Regards herge.
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

azdps

thank you both. i was able to figure it out.