The shortest way could be this.
String photo = "0000005000000050FF191818FF151715FF111413FF0E100FF2A2322FF292221"; // adds a dummy byte at the start to avoid truncation of leading zeros. byte[] bytes = new BigInteger("10" + photo, 16).toByteArray(); System.out.println(Arrays.toString(bytes));
prints
[1, 0, 0, 0, 5, 0, 0, 0, 5, 15, -15, -111, -127, -113, -15, 81, 113, 95, -15, 17, 65, 63 , -16, -31, 0, -1, 42, 35, 34, -1, 41, 34, 33]
source share