Jkohn said:
would it be logical to assume the following:
since the remainder of n/2 [until x^0]
can be used to get binary code
example
6 3 0
3 1 1
1 0 1
110=6
can I assume this for all bases?
ty!
(assuming integer divide that truncates the number)
For 6 from base 10 to base 2:
6%2 = 0, 6/2 = 3
3%2 = 1, 3/2 = 1
1%2 = 1, 1/2 = 0
You stop at zero on the second and the list of numbers reversed is the binary: 110
Just like you did.
This works for all integer bases:
For 47 from base 10 to base 16 (using A-F for 10-15):
47%16 = 15, 47/16 = 2
2%16 = 2, 2/16 = 0
Hex: 2F
If you want a higher base, you have to have something to represent it, or you just put a comma between numbers like (2,15) instead of 2F or 0x2F
I guess you could call it decimal to other base conversion. To convert back is a little more complicated. You can do the same in that base (which can be confusing if you don't have a table), but it's easier to represent each numeral by the power representation of the base in that location and add it up to convert back, because you can do that in decimal.
Oh, like Kael42 said. Base can really be anything. You may want to stick to positive integer bases that are 2 are larger (2,3,4,5,...) until you get an idea how it works first. Well, you can do unary also, but then you'll have a lot of 1's across the screen.