tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Uncommons Maths > Byte Array to Hex String

Byte Array to Hex String 

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.

File Name  :  
com/bethecoder/tutorials/uncommons/Bytes2HexStringTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
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);
  }

}
   

It gives the following output,
[1, 7, -39, -47]
0107D9D1


                    Print

   



Books Recommendation

 
 
bl  br