QUOTE(Locke37 @ 3 Jul, 2008 - 03:05 PM)

Well, yes there are, but normally, there are assignments in classes to make these methods and such yourself. I had something like that in my java class, and I looked up the methods to do it, but my teacher said write the code myself...don't use the methods...

Binary: 1 bit per number
Octal: 3 bits per number
Hexadecimal: 4 bits per number
Let's take the number 47:
Binary: 00101111
Each binary number represents a power of 2: the rightmost is 2^1, the next is 2^2, and so on
For every octal "place", you take the rightmost 3 bits from the binary number:
111 = 1*4 + 1*2 + 1*1 = 7
101 = 1*4 + 0*2 + 1*1 = 5
00 = 0*2 + 0*1 = 0
So 47 decimal = 00101111 binary = 57 octal
Hexadecimal is similar, except you take 4 bits and replace any number higher than 9 with A-F:
Decimal 47 =
Binary 00101111
1111 = 1*8 + 1*4 + 1*2 + 1*1 = 15 = F
0010 = 0*8 + 0*4 + 1*2 + 0*1 = 2
So 47 decimal = 2F hexadecimal
---
Now surely you can turn this into an algorithm?
This post has been edited by JeroenFM: 4 Jul, 2008 - 01:05 AM