Here you can find the source of bytesToHexChars(byte[] bytes)
Parameter | Description |
---|---|
bytes | TODO |
static char[] bytesToHexChars(byte[] bytes)
//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; } }