Convert byte array to Hex Char Array - Java java.lang

Java examples for java.lang:String Hex

Description

Convert byte array to Hex Char Array

Demo Code


//package com.java2s;

public class Main {


    public static char[] toHexCharArray(byte[] input) {
        int m = input.length;
        int n = 2 * m;
        int l = 0;
        char[] output = new char[n];
        for (int k = 0; k < m; k++) {
            byte v = input[k];
            int i = (v >> 4) & 0xf;
            output[l++] = (char) (i >= 10 ? ('a' + i - 10) : ('0' + i));
            i = v & 0xf;/*from   w w  w  .  j av a  2s  . c  o m*/
            output[l++] = (char) (i >= 10 ? ('a' + i - 10) : ('0' + i));
        }

        return output;
    }
}

Related Tutorials