Convert byte to Hex by shifting bits - Android java.lang

Android examples for java.lang:Hex

Description

Convert byte to Hex by shifting bits

Demo Code


public class Main{

    private static String byteHEX(byte ib) {
        char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'A', 'B', 'C', 'D', 'E', 'F' };
        char[] ob = new char[2];
        ob[0] = Digit[(ib >>> 4) & 0X0F];
        ob[1] = Digit[ib & 0X0F];/*from   w w w  . j  a v  a 2s .c  om*/
        String s = new String(ob);
        return s;
    }

}

Related Tutorials