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.convertBytesToHexString() API.
package com.bethecoder.tutorials.uncommons; import java.nio.ByteBuffer; import java.util.Arrays; import org.uncommons.maths.binary.BinaryUtils; public class Bytes2HexStringTest { /** * @param args */ public static void main(String[] args) { //Convert number to byte array byte [] bytes = ByteBuffer.allocate(4).putInt(17291729).array(); System.out.println(Arrays.toString(bytes)); //Convert byte array to hex string String hexStr = BinaryUtils.convertBytesToHexString(bytes); System.out.println(hexStr); } }
[1, 7, -39, -47] 0107D9D1