ZionSV

Mar 5, 2009, 01:45 AM

Hello, I am in an intro to programming class and I'm stuck on a problem.

I am supposed to turn any number, i, into base k from 2 - 16

now I can do it with base 1 - 9 with this code

int i, k;

int v = 1;

System.out.print("\n\t Enter an integer: ");

keysIn = keyboard.next();

i = Integer.parseInt(keysIn);

System.out.print("\n\t Enter the base: ");

keysIn = keyboard.next();

k = Integer.parseInt(keysIn);

while (v <= i) {

v *= k;

}

while (v > 0) {

if (i < v) {

System.out.print(0);

}

else {

int output = (i - (i % v))/v;

System.out.print(output);

i -= v*output;

}

v = v/k;

}

The problem is I don't know how to use the letters A -F for base 10 - 16

Any help would be greatly appreciated, btw sorry this is such a noob question, I'm not very good at this yet.. :\

I am supposed to turn any number, i, into base k from 2 - 16

now I can do it with base 1 - 9 with this code

int i, k;

int v = 1;

System.out.print("\n\t Enter an integer: ");

keysIn = keyboard.next();

i = Integer.parseInt(keysIn);

System.out.print("\n\t Enter the base: ");

keysIn = keyboard.next();

k = Integer.parseInt(keysIn);

while (v <= i) {

v *= k;

}

while (v > 0) {

if (i < v) {

System.out.print(0);

}

else {

int output = (i - (i % v))/v;

System.out.print(output);

i -= v*output;

}

v = v/k;

}

The problem is I don't know how to use the letters A -F for base 10 - 16

Any help would be greatly appreciated, btw sorry this is such a noob question, I'm not very good at this yet.. :\