1

I have a java program where a read a identitynumber. Like "1234567" Now i want to convert that ascii value to a hexadecimal value and put that in a hexadecimal byte array like this :

byte[] bytes = {0x02, 0x0b, 0x39, 0x36, 0x31, 0x31, 0x32, 0x36, 0x31, 0x39, 0x39, 0x34, 0x37, 0x32, 0x03};

Problem is .. I have no idea how that i can do that .. Have you a solution or tips ? Thanks !

 String foo = receivedData.substring(10,21);
               BigInteger data = new BigInteger(foo);
Jens G
  • 19
  • 6
  • What exactly do you want? Hex is just a representation of a number, as is decimal or octal. So just store each digit of the number as an element in an array of type `int` or in a Collection of type `Integer`. There is no such data type as "hex" nor "decimal" nor "octal"; all those are representations of the same integer type. – Basil Bourque Oct 31 '17 at 15:28
  • for example i have the number 1234567. This is a ascii number. Now i want to split this number into different int like 1 2 3 4 .. Then i want to convert that number for example '1' to a hexadecimal value '31'. At last i want to put the value in the byte array like 0x31 – Jens G Oct 31 '17 at 15:31
  • Have you tried that cool website called Google? 1st result - https://www.mkyong.com/java/how-to-convert-hex-to-ascii-in-java/ – Michael Peacock Oct 31 '17 at 16:05

0 Answers0