Java Byte Array to Hex bytesToHex(final byte[] bytes)

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

Description

Wandelt ein Byte-Array in eine hexadezimale Darstellung um

License

Open Source License

Parameter

Parameter Description
bytes Byte-Array

Return

Hex-Darstellung, z.B. "4711af2b"

Declaration

public static String bytesToHex(final byte[] bytes) 

Method Source Code

//package com.java2s;
/*//from   w  w w. j  av  a  2s.  c  o m
 * Copyright 2016 by Kappich Systemberatung Aachen
 * 
 * This file is part of de.bsvrz.dav.daf.
 * 
 * de.bsvrz.dav.daf 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.
 * 
 * de.bsvrz.dav.daf 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 de.bsvrz.dav.daf; If not, see <http://www.gnu.org/licenses/>.
    
 * Contact Information:
 * Kappich Systemberatung
 * Martin-Luther-Stra?e 14
 * 52062 Aachen, Germany
 * phone: +49 241 4090 436 
 * mail: <info@kappich.de>
 */

public class Main {
    /**
     * Wandelt ein Byte-Array in eine hexadezimale Darstellung um
     * @param bytes Byte-Array
     * @return Hex-Darstellung, z.B. "4711af2b"
     */
    public static String bytesToHex(final byte[] bytes) {
        StringBuilder stringBuilder = new StringBuilder(bytes.length * 2);
        for (byte b : bytes) {
            stringBuilder.append(Character.forDigit(0xF & (b >>> 4), 16));
            stringBuilder.append(Character.forDigit(0xF & b, 16));
        }
        return stringBuilder.toString();
    }
}

Related

  1. bytesToHex(byte[] in)
  2. bytesToHex(byte[] raw)
  3. bytesToHex(byte[] raw)
  4. bytesToHex(byte[] raw)
  5. bytesToHex(final byte[] b)
  6. bytesToHex(final byte[] bytes)
  7. bytesToHex(final byte[] bytes)
  8. bytesToHex(final byte[] bytes)
  9. bytesToHex(final byte[] bytes, final boolean toLowerCase)