-
help needed urgently
hi friends,
i'm trying to write a program that converts decimal value into any (binary,octal and hexa decimal)
i'm printing the result but i coudn't convert hexa decimal value
please help me
here is my code
public class decx
{
public static void main(String args[])
{
String output=decx.decToBase(28,2);
String output1=decx.decToBase(234,8);
String output2=decx.decToBase(2989,16);
System.out.println(output);
System.out.println(output1);
System.out.println(output2);
}
static String decToBase(int n,int radix)
{
String str=" ";
String str1="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i;
int rem;
while(n!=0)
{
i=n/radix;
rem=n%radix;
System.out.println(rem);
n=i;
if(rem<=9)
{
str=str+rem;
}
else
{
rem=str1.charAt(rem);
str=str+rem;
}
}
return str;
}
}
-
Can you tell me the way you try to convert decimal to hexadecimal values in your code.