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

Convert 64-bit integer to another number base

Convert 64-bit integer to another number base

Convert 64-bit integer to another number base

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."

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