-1

I am trying to convert hex string "F08282AC" to char using below code

Integer.parseInt(hex, 16)

but it throws

Exception in thread "main" java.lang.NumberFormatException: For input string: "F08282AC"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:583)

How can I convert it to char?

dashenswen
  • 540
  • 2
  • 4
  • 21

1 Answers1

-1

1) Characters can only hold 16 bits.

The number you have would far exceed that. If you meant a character array, you could use the String.valueOf(Long.parseLong(hex, 16)).toCharArray()

In parts, we convert the number to base 10, then convert it to a string, then convert it to a character array of numbers.

Peter S
  • 827
  • 1
  • 8
  • 24