Java Byte Array to Hex String bytesToHexChars(byte[] bytes)

Here you can find the source of bytesToHexChars(byte[] bytes)

Description

Transforms bytes to an array of hex characters representing the nibbles

License

Open Source License

Parameter

Parameter Description
bytes TODO

Return

TODO

Declaration

static char[] bytesToHexChars(byte[] bytes) 

Method Source Code

//package com.java2s;
/*// w ww  .j  av a  2  s. co m
 * Copyright (c) 2016 Ian Bondoc
 *
 * This file is part of Djeng
 *
 * Djeng is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version.
 *
 * Djeng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 *
 */

public class Main {
    private static final String HEX = "0123456789ABCDEF";

    /**
     * Transforms bytes to an array of hex characters representing the nibbles
     *
     * @param bytes TODO
     * @return TODO
     */
    static char[] bytesToHexChars(byte[] bytes) {
        char[] chars = new char[bytes.length * 2];
        int charPos = chars.length - 1;// LSB

        for (int bytePos = bytes.length - 1; bytePos >= 0; bytePos--) {
            chars[charPos--] = HEX.charAt(bytes[bytePos] & 0x0f);
            chars[charPos--] = HEX.charAt((bytes[bytePos] & 0xf0) >> 4);
        }
        return chars;
    }
}

Related

  1. bytes_to_hex(byte[] b)
  2. bytes_to_hex(byte[] bytes)
  3. bytesToHexAppend(byte[] bs, int off, int length, StringBuffer sb)
  4. bytesToHexChars(byte[] bytes)
  5. bytesToHexChars(byte[] bytes)
  6. bytesToHexChecksum(byte[] byteArr)
  7. bytesToHexDelimeter(byte[] data, String delimeter)
  8. bytesToHexFormatted(byte[] bytes)
  9. bytesToHexSpaced(byte[] bytes)