Convert 64-bit integer to another number base
Convert 64-bit integer to another number base
(OP)
Hi,
I have a 64-bit number stored in a variable called "num".
I try to convert it to another base, i.e hex. But when I stored the 64-bit in EDX:EAX and divide bay EBX (which is 16) to get the remainder (stored in EDX), the quotient is too big to fit in EAX. I think there could be a way to do it by shifting.
Can anybody help me?
Thanks alot.
I have a 64-bit number stored in a variable called "num".
I try to convert it to another base, i.e hex. But when I stored the 64-bit in EDX:EAX and divide bay EBX (which is 16) to get the remainder (stored in EDX), the quotient is too big to fit in EAX. I think there could be a way to do it by shifting.
Can anybody help me?
Thanks alot.
RE: Convert 64-bit integer to another number base
Shl(x,n)= Shift Left the number X by n bits
Shl(x,n)= x * 2^n
Shr(x,n)= Shift Left the number X by n bits
Shr(x,n)= (int)(x / 2^n)
Since 16=2^4,
X / 16 = X / 2^4 = SHL (X,4)
As I mentioned in your 'Ascii string to 64-bit integer' question, multi-word shifting is done one bit at a time and requires the use of RCL and RCR as well as SHR and SHL.
Multi-word division by any number is a pain BTW so please don't ask me that...
To get the remainder of (x / 2^n)...
(let x % 2^n = remainder of x / 2^n)
x % 2^n = x AND (2^n - 1)
So if you need the remainder of x % 16, you do:
X AND 15
Note that a remainder can be taken via an AND operation if, and only if, the divisor is a power of two!!!
"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."