Here you can find the source of bytesToHex(byte... bytes)
Parameter | Description |
---|---|
bytes | Bytes to convert. |
public static String bytesToHex(byte... bytes)
//package com.java2s; /*/*from www.j a v a 2 s .c o m*/ * Copyright (C) 2015 J.S. TESSIER * * This file is part of java-rf24. * * java-rf24 is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * java-rf24 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with java-rf24. If not, see <http://www.gnu.org/licenses/lgpl-3.0.html>. */ public class Main { /** * Convert bytes to HEX values in a string ("null safe"). * * @param bytes Bytes to convert. * @return The result string. */ public static String bytesToHex(byte... bytes) { if (bytes == null) { return null; } final char[] hexArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; char[] hexChars = new char[bytes.length * 2]; for (int i = 0; i < bytes.length; i++) { hexChars[i * 2] = hexArray[(Byte.toUnsignedInt(bytes[i]) >>> 4)]; hexChars[i * 2 + 1] = hexArray[bytes[i] & 0x0F]; } return new String(hexChars); } }