Java Hex Calculate toHexBytes(byte[] toBeConverted)

Here you can find the source of toHexBytes(byte[] toBeConverted)

Description

to Hex Bytes

License

Apache License

Declaration

public static byte[] toHexBytes(byte[] toBeConverted) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    static final byte[] HEX_BYTES = new byte[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c',
            'd', 'e', 'f' };

    public static byte[] toHexBytes(byte[] toBeConverted) {
        if (toBeConverted == null) {
            throw new NullPointerException("Parameter to be converted can not be null");
        }/*from ww  w . j av a 2 s  . c o m*/

        byte[] converted = new byte[toBeConverted.length * 2];
        for (int i = 0; i < toBeConverted.length; i++) {
            byte b = toBeConverted[i];
            converted[i * 2] = HEX_BYTES[b >> 4 & 0x0F];
            converted[i * 2 + 1] = HEX_BYTES[b & 0x0F];
        }

        return converted;
    }
}

Related

  1. toHexByte(int bite)
  2. toHexByte(int i)
  3. toHexByteArray(final byte[] buffer)
  4. toHexBytes(byte[] bytes)
  5. toHexBytes(byte[] data)
  6. toHexChar(byte[] bArray)
  7. toHexChar(char ch, StringBuffer sb)
  8. toHexChar(int b)
  9. toHexChar(int digit)