Java Hex Calculate toHexBytes(byte[] data)

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

Description

to Hex Bytes

License

Open Source License

Declaration

public final static char[] toHexBytes(byte[] data) 

Method Source Code

//package com.java2s;
/*/*from ww w. j  a  va2s.c om*/
 * Copyright 2013-2023 "Peng Li"<aqnote@qq.com>
 * Licensed under the AQNote License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.aqnote.com/licenses/LICENSE-1.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

    public final static char[] toHexBytes(byte[] data) {
        if (data == null)
            return null;
        int len = data.length;
        char[] out = new char[len << 1];
        // two characters form the hex value.
        for (int i = 0, j = 0; i < len; i++) {
            out[j++] = hexDigits[(0xF0 & data[i]) >>> 4];
            out[j++] = hexDigits[0x0F & data[i]];
        }
        return out;
    }
}

Related

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