×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Hexadecimal To Decimal convertion

Hexadecimal To Decimal convertion

Hexadecimal To Decimal convertion

(OP)
Please Help Me out I want X86 Assembly Snippet to convert Hexadecimal Number To its Decimal Counterpart

Thanx In Advance

Shantanu

RE: Hexadecimal To Decimal convertion

I presume that the hexadecimal and decimal are in ASCII string format?

The technique here is to convert the hexadecimal string into an integer, and then to convert the integer to a decimal string.


hexstringtoint proc
;input: si=start of sz string
;output: si=end of sz string, ax=integer
push bx

mov ax,0
mov bx,0
loop1hsti:
;get a byte from the string
mov bl,byte ptr [si]
;check if it's end of string
test bl,0ffh
jz outofloop1hsti
;check if it's an alphabetical character
cmp bl,64
jbe notalpha
;adjust alpha characters
sub bl,7
notalpha:
;determine the value of the digit we just got
and bl,0fh
;shift our accumulator
shl ax,4
add ax,bx
inc si
jmp loop1hsti
outofloop1hsti:
pop bx
ret
hexstringtoint endp



decimaldata dw 10000,1000,100,10,1
inttodecstring proc
;input: ax=integer to output, si=string space to work in
;output: si=start of decimal string
;NOTE: output string has leading zeros!!!
push di
push bx
push cx
push dx

mov bx,si
mov di,0
loop1itds:
;divide by powers of tens
mov cx,decimaldata[di]
mov dx,0
div cx
;convert result to a digit string
add al,40h
mov byte ptr [di][bx],al
;transfer remainder to ax
mov ax,dx
add di,2
cmp di,10
jb loop1itds

pop dx
pop cx
pop bx
pop di
ret
inttodecstring endp


Anyway those two procedures are off the top of my head, better check through the logic carefully before cutting and pasting it.

Also it is up to YOU to input the data and output it, and to filter it too so that you don't get garbage.  He he those are just routines!!

(Seems kind of a lot just to convert hex to dec, eh?  Don't busk it, it gets harder when you are making an application.)

"Information has a tendency to be free.  Which means someone will always tell you something you don't want to know."

RE: Hexadecimal To Decimal convertion

<bump>

"Information has a tendency to be free.  Which means someone will always tell you something you don't want to know."

RE: Hexadecimal To Decimal convertion

<bump>

Say... maybe I should actually write a FAQ for this?  Doing integer to string and string to integer conversions...  What d'you-all think?

It's just that I'm just a tad too lazy to write a FAQ...

"Information has a tendency to be free.  Which means someone will always tell you something you don't want to know."

RE: Hexadecimal To Decimal convertion

A faq would be *extremely* helpful, both for myself and I would presume many others as well.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close