×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• 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.

(OP)

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
sub bl,7
notalpha:
;determine the value of the digit we just got
and bl,0fh
;shift our accumulator
shl ax,4
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
mov byte ptr [di][bx],al
;transfer remainder to ax
mov ax,dx
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.

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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!