"Don't tell me how hard you work. Tell me how you get done."
- James J. Ling

Converting hexadimal to binary

August 11, 2006

This is a shorter and lazier version of hex to binary conversion. It displays right away the binary equivalent of a valid hexadecimal and waits user to press enter key to end. Thanks to sir for the convert algo…hehe:) 

check:
    mov ah, 00
    int 16h

    cmp ah, 1ch                               ; scan key for enter key
    je exit

    cmp al, ‘0′
    jb check
    
    cmp al, ‘9′
    ja ucase
    
    sub al, 30h
    call convert
    jmp check

ucase:
    cmp al, ‘A’
    jb check

    cmp al, ‘F’
    ja lcase
    
    sub al, 37h
    
    call convert
    
    jmp check

lcase:
    cmp al, ‘a’
    jb check
    
    cmp al, ‘f’
    ja check
    
    sub al, 57h
    
    call convert

    jmp check
     
exit:
    int 20h
    
loop check

;———————–convert——————————
convert:

    mov ch, 4        ; 4 bits
    mov cl, 3        
    mov bl, al
    
    xxx:
        mov al, bl
        shr al, cl    
        and al, 01    ; bit masking- isolate least bit 0
    
        add al, 30h

        mov ah, 02    ; display binary equivalent
        mov dl, al
        int 21h
    
        dec cl        
        dec ch
    
    jnz xxx
    
    mov dl, ‘ ‘
    int 21h
    ret

Posted by phengpheng at 2:06 pm | permalink

All comments are moderated. Your comments will not appear here unless approved by the blog owner. Thank you.

Add a comment








     

August 2006
M T W T F S S
« Jul   Sep »
 123456
78910111213
14151617181920
21222324252627
28293031  

About Me

A Computer Science graduate who is a fanatic in assembly, java, and j2me programming. Developed BlueVoice system (Direct Voice Communication in Mobile Phones), this system allows mobile users to experience FREE VOICE CALLS

Subscribe

Technorati
Bloglines

Tagboard

tinnitus treatment:

thanks You sure do know what your’e talking about. Man, this blog is just great! I cant wait to read more of what youv’e got to say. Im really happy that I came across this when I did because I was really starting

phengpheng:

Haven’t managed my blog for a long time already because I’m so busy now… Sorry to cause you guyz trouble…

Jun Mark:

hoW tO creaTE a PrOGram thAT woULD oUTpuT ascii table???

Jun Mark:

pLZ anSwer mY qUEstions

cutieGurl:

how to convert binary to hexadecimal, decimal and octal?????????please. answer me??????????

mary ann:

kuya, ung binary to decimal converter nyo. mali man? ung sa mga compare mo. ung may 0,9,A,F etc… bad character lumalabaspls rep asap po. tnx

carol:

how to convert decimal to binary to octal and hexadecimal

Galwin:

been here!

galwin:

nice site. hope you could visit mine, too.

pathy:

FRIENDS FOREVER!! Miss you na!!!

ridvan:

aus, i seldom see lady programmers. hehe. keep it up. and oh yeah, i guess i saw you during the MICT Quiz Show held in cdo. :)
keep up the codes!

phengpheng:

I miss updating this blog… Sana may time and pc ako to learn new stuffs aside from my work…

support:

Congratulations, you’ve just completed the installation of this shoutbox.

pheng:

uy! you’re here again!

Jay:

Woooohhhh orange…sweat… nakakasilaw! hehe :)

jay:

tagboard flood hehe sensya… had nothing fun to do. :)

pheng:

jaaaaayyyyy….:) ketal man?:)

niel:

no spamming please :p hehehe joke lang jay.

Jay:

Uyyyyyy!!!! Grraaaaaaaiiiinnnneeee
:)
Sssshhhh, el sikret! :)
Niiiiiiiiiiiiieeeeeel
Sup dude!!!!
Paaaaaaaaaaaaaathy
Ketal!?

niel:

ei pheng! :D slick-elegant layout! love it!

Leave a message ▼