0

I am new to Java trying to code a decimal to hexadecimal converter. The converter almost works but the numbers are flipped so I need to fix that but it wont let me due to the code having Strings. Is there anyway to fix this or an easier way that I am missing?

Thank you.

  int temp, reverse;
  String digits = "0123456789ABCDEF";
  String hexa = " ";

  while (myDecimal > 0){
    int x = myDecimal % 16;
    hexa = hexa + digits.charAt(x);
    myDecimal = myDecimal / 16;
  }
  System.out.println(hexa);

  temp = hexa % 10;
  reverse = reverse * 10 + temp;
  hexa = hexa / 10;
  • 2
    Possible duplicate : http://stackoverflow.com/questions/7569335/reverse-a-string-in-java – YounesM Jan 19 '16 at 03:18
  • 2
    why not change `hexa + digits.charAt(x)` to -> `digits.charAt(x) + hexa;` Instead of appending in the last, append in the start. – YoungHobbit Jan 19 '16 at 03:19

1 Answers1

0

hexa + digits.charAt(x) to -> digits.charAt(x) + hexa