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

Base Conversion

Base Conversion

Base Conversion

Is there an easy way to convert an integer number (base-10)to another base? (like base-5)

RE: Base Conversion

yes it is easy
you divide the 10 base number out of 5 or any base you want then take the remainder as the left digit redo with the dividend
like the code below

     mov eax, (the wished number)
     mov cx, 14
    xor edx, edx (or extend the sign by cxd instruction i think)
    div word ptr 5
    shl edx,12
    shld memory, edx, 4
    mov  edx, eax
    loop a:
 this is example the result is the memory value clear it before use
mov cx, 14   14 if base 5 it must be changed if not 5

RE: Base Conversion

Awesome. Thanks!

RE: Base Conversion

sorry i gave you a false code example, because i usually did; dividing by ten's power (to convert from hex to decimal and display a bounded num) and put remainder in memory from left to right.
yesterday my brain was off; i mixed the both ideas
ok, never mind
in your case you must divide by the base then you put the remainder in memory from right to left.
the right code is:
    mov      eax, (wished number)
    xor   edx, edx
    div   word ptr 5 (base)
    mov   memory, dl
    inc   memory(memory=num after converting)
    cmp   eax, 0
    jz    b:
    mov   eax, edx
    jmp   a:
nb1: number of 3 digit in decimal base gives number of 7 digit at least in binary base; converting is giving a new representation to any number so you should give memory enough size
nb2: num in base 5 is represented by 0 1 2 3 4 ; you can leave the remainder in nibble you don't need a byte for each digit however if the base is > 8 you should use bytes     

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