I would like to be able to take a hex number and make it in to whatever i want. I wrote a few days ago a little process that can take ascii hex or decimal input and make it hex nunmbers and visaversa but it only worked for one byte at first only up to 99. I figured a way to work with larger numbers but it is very complicated and requires a conversion table. It is also limited to intigers. I have only put the first method in code so far. The other is extreamly complicated and Im certain there must be a better way. What I really want is to know how to do conversions to and from a DWORD hex to everything else. includeing non intiger decimal, and negatives. so i can show them in ascii. If no one knows where I can get information on this then possibly some source or even a already compiled dll or prog. anything will be helpfull thank's :alright:
Posted on 2002-08-18 01:08:11 by dionysus
This is a very common thing to do and there are hundreds of examples on this board (this is not hyperbole). With basic arithmetic and an ASCII table, you can do all the conversions you would like. Please look at the FAQ and search the board.
Posted on 2002-08-18 01:30:18 by bitRAKE
thanks anyway... or not
Posted on 2002-08-18 01:54:06 by dionysus
Have a look at the "htodw" procedure in the MASM32 library, the source code is there for you to have a look at.

Ricky's advice is good advice in that much of this stuff gets posted in the source code forum so don't be afraid to have a look around as you will run into some good code if you go looking for it.


Posted on 2002-08-18 03:14:41 by hutch--
I know this probably isn't the most efficient way to do it but what I did was divided the hex number by the base of the decimal number system, then I took the remainder and placed it in a buffer, I continued dividing it by 10 and adding the remainder to the buffer untill there were no numbers left. then when I was finished I reversed the buffer and it had decimal numbers.  I also added '0' to the numbers so that they were in ascii format, and when I moved them to the buffer I moved the whole of dl so that it was an unpacked number.
This is the bit of code. The original numbers to multiplied together are in num1 num2 the hex answer is in answer and the decimal answer is in AsciiAnswer.

;add two variables in the mmx registers
movapd xmm0,
movapd xmm1,xmm0
movapd xmm0,
addpd xmm0,xmm1
movapd ,xmm0

;save the registers windows likes to use so that we can give them back when
;were finished.
push esi
push edi
push ebx

;we need to direct our input and output and store the size of how much data
;we are moving.
mov esi,offset
mov edi,offset

;clear the junk out of eax and begin our hex to decimal conversion loop
xor eax,eax

;Load a byte into al *now the fun starts .. NOT

xor edx,edx
mov ,eax

.if eax > 0
xor edx,edx
;this divides by the 10th limit of our decimal system.
;it gives us our last digit. is equal to A or 10 decimal.

;save the last digit.;should not be more than 9 as we are dividing by 10.
;so it is definately our last digit.

add dl,'0'
mov ,dl
inc edi
jmp top

;the next part reverses the numbers.
mov esi,offset
mov edi,offset

mov ecx,
add esi,
sub esi,1
.if counter==0
mov ax,
mov ,al
.while counter > 0
mov al,
dec esi
mov ,al
inc edi

;restore the registers windows likes to use.
pop ebx
pop edi
pop esi

Posted on 2006-08-05 00:20:40 by phase_verocity
includeing non intiger decimal

After you become more familiar with the conversion of integers, and you want to handle non-integer decimals without using the FPU with its floating point format, you may want to look at fixed point decimal math. The following would get you started:


Eventually, you may need to use floating point numbers and the FPU. The following should get you started.


Posted on 2006-08-05 21:44:54 by Raymond