Uncommons Maths is a java library with nice math utilities and random number generators. This requires the library uncommons-maths-1.2.2.jar to be in classpath. The following example shows using BinaryUtils.convertHexStringToBytes() API.
package com.bethecoder.tutorials.uncommons; import java.nio.ByteBuffer; import java.util.Arrays; import org.uncommons.maths.binary.BinaryUtils; public class HexString2BytesTest { /** * @param args */ public static void main(String[] args) { String hexStr = "0107D9D1"; //Convert hex string to byte array byte [] bytes = BinaryUtils.convertHexStringToBytes(hexStr); System.out.println(Arrays.toString(bytes)); //Convert byte array to number System.out.println(ByteBuffer.wrap(bytes).getInt()); } }
[1, 7, -39, -47] 17291729