Hello everyone,
I've just started with Java recently, and i'm just trying to code some in Java. I came up with this idea for an app to convert decimal -> hexadecimal, decimal -> binary and vice versa. I managed to write the code for decimal -> binary
if ((radioButton1.getState() == true) && (radioButton5.getState() == true))
{
do
{
if (number % 2 == 0)
result = "0" + result;
else
{
result = "1" + result;
number--;
}
number = number / 2;
}
while (number > 0);
textField2.setText(result);
}
I've also been working on decimal -> hexadecimal conversion
if ((radioButton1.getState() == true) && (radioButton6.getState() == true))
{
int digit = number.charAt();
if (digit>='a' || digit>='A')
{
if (digit=='a' || digit=='A')
digit=10;
else if (digit=='b' || digit=='B')
digit=11;
else if (digit=='c' || digit=='C')
digit=12;
else if (digit=='d' || digit=='D')
digit=13;
else if (digit=='e' || digit=='E')
digit=14;
else if (digit=='f' || digit=='F')
digit=15;
}
int bla = number / 16;
int rest = number - bla;
resultaat = String.valueOf(rest+bla);
textField2.setText(resultaat);
}
The problem is, that the decimal -> hexadecimal conversion does not work. The error given is "Can't invoke a method on a int. int digit = number.charAt();
Now my question is, how do i get the dec->hex conversion working? And do you guys have some tips (guidelines) to point me in the right direction for the binary-> decimal conversion, cause i'm really stuck on that one.
Thanks alot in advance,
Kevin