byte To Hex - Java File Path IO

Java examples for File Path IO:Byte Array

Description

byte To Hex

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte someByte = 2;
        System.out.println(java.util.Arrays.toString(byteToHex(someByte)));
    }//from   w  w  w .  jav a 2s.c o m

    private final static char[] hexArray = "0123456789ABCDEF".toCharArray();

    public static char[] byteToHex(byte someByte) {
        char[] hexChars = new char[2];
        int v = someByte & 0xFF;
        hexChars[0] = hexArray[v >>> 4];
        hexChars[1] = hexArray[v & 0x0F];
        return hexChars;
    }
}

Related Tutorials