Java's Integer class has methods toBinaryString() and toHexString().
Here is an example of how to convert a number into binary (base 2):
43 / 2 = 21 R 1 21 / 2 = 10 R 1 10 / 2 = 5 R 0 5 / 2 = 2 R 1 2 / 2 = 1 R 0 1 / 2 = 0 R 1 END
The answer reads the remainders bottom to top: 101011
The algorithm for hexadecimal (base 16) is similar, but a "0x" must be prepended. Base 16 also has the following digits: 0123456789abcdef, where a--f represent the numbers 10 through 15 in base 10. The number 43 would be 0x2b in hexadecimal.
Write toBinaryString() and toHexString(), both of which return strings representing numbers in the appropriate bases.