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

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

Originally Posted by brewbuck
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&#37;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

2. Originally Posted by Sygo
2. Divide n by p to get result q and remainder r.
This line, in actual code, would look like this:

Code:
```q = n / p;
r = n % p;```

3. Originally Posted by brewbuck
This line, in actual code, would look like this:

Code:
```q = n / p;
r = n % p;```

ok I know what you ment in code terms thats what I just wrote in the line ahead so p=16 the base or power correct

so I'll explain it in code terms
n=921;
p=16;
q=n/p;
r=n%p;

is that what you mean??????? if so we can stop doing the infinate loop now ha hahaha.

4. So understanding the concept of converting the remainders 10-15 in Hex A-F