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
Thanx In Advance
Shantanu
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS Contact USThanks. We have received your request and will respond promptly. Come Join Us!Are you a
Computer / IT professional? Join Tek-Tips Forums!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting Guidelines |
Hexadecimal To Decimal convertion
|
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.
RE: Hexadecimal To Decimal convertion
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
"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
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