Java Byte Array to Hex byteToHex(byte b)

Here you can find the source of byteToHex(byte b)

Description

byte To Hex

License

Open Source License

Declaration

private static char[] byteToHex(byte b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /** Most significant bits mask for binary operations */
    public static final int MOST_SIGNIFICANT_MASK = 0xFF;
    /** Least significant bits mask for binary operations */
    public static final int LEAST_SIGNIFICANT_MASK = 0x0F;
    /** {@code char[]} in which each position contains the hex value textual representation */
    protected static final char[] hexArray = "0123456789ABCDEF"
            .toCharArray();

    private static char[] byteToHex(byte b) {
        char[] hexChars = new char[2];
        int v = b & MOST_SIGNIFICANT_MASK;
        hexChars[0] = hexArray[v >>> 4];
        hexChars[1] = hexArray[v & LEAST_SIGNIFICANT_MASK];
        return hexChars;
    }//from  ww  w  .j  a  v  a 2 s.c o m
}

Related

  1. bytesToHex(final byte[] bytes, final int position, final int length)
  2. bytesToHex(StringBuffer buff, byte[] src, int start, int end)
  3. bytesToUnsignedHexes(byte[] bytes)
  4. byteToBcd(byte src)
  5. byteToHex(byte b)
  6. byteToHex(byte b[])
  7. byteToHex(byte b[])
  8. byteToHex(byte bytes[])
  9. byteToHex(byte data)