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 {
    private static char[] byteToHex(byte b) {
        int unsignedByte = (int) b - Byte.MIN_VALUE;
        return new char[] { unsignedIntToHex((unsignedByte >> 4) & 0xf),
                unsignedIntToHex(unsignedByte & 0xf) };
    }// w w w  . ja v  a2 s  .  c  o m

    private static char unsignedIntToHex(int i) {
        if (i >= 0 && i <= 9) {
            return (char) (i + 48);
        } else if (i >= 10 && i <= 15) {
            return (char) (i + 87);
        } else {
            throw new IllegalArgumentException(
                    "Invalid hex int: out of range");
        }
    }
}

Related

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