Thread: Dec to Hex, Hex fraction to Dec fraction, and Dec fraction to Hex fraction conversion

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #16
    Registered User
    Join Date
    Mar 2008
    Posts
    10
    0. Let n = the number you are converting
    1. Find p, the highest power of 16 which fits into n.
    2. Divide n by p to get result q and remainder r.
    3. Output q, which is a value between 0 and 15, as the next digit of the hex representation
    4. Let n = r
    5. Let p = p / 16
    6. If p > 0, go to step 2

    Quote Originally Posted by brewbuck View Post
    You need to do both, actually. The quotient is used to produce the digit. The remainder is used as the next value to produce the next digit. I'm talking about step 2. The part where p is divided by 16 (step 5) is unrelated. It is just used to move down a power.

    For the part about converting between a number in the range 0..15 and a hex digit, there are multiple ways, so try something first and if you have trouble we'll discuss.
    ok I understand that you find p%16 which is the next digit or remainder as you where saying in step one would be just be represented as 16 in the case of the hightest power of 16.

    in ohter words r=n%16 or r=n/16 I guess I'm confused by the way you word it. cuz I know how to find the conversion from decimal to hex in the form of remainder for example
    921 in decimal
    what you mean by p=16 correct
    q=921%16=57//next digit
    r=921/16=57.5625 then .5625*16=9 remainder
    q=57%16=3//next digit
    r=57/16=3.5976 then .5976*16=9 remainder
    q=3%16=3 //next digit but in this case remainder
    solution is 399 in hex from 921 in dec
    Last edited by Sygo; 03-25-2008 at 12:31 PM.

Popular pages Recent additions subscribe to a feed