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

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

Description

bytes To Hex Formatted

License

Open Source License

Declaration

public static String bytesToHexFormatted(byte[] bytes) 

Method Source Code

//package com.java2s;
/**/*from w w  w  .j av  a 2s  . c om*/
 * Copyright (c) 2010-2015, openHAB.org and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

public class Main {
    final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();

    public static String bytesToHexFormatted(byte[] bytes) {

        char[] hexChars = new char[bytes.length * 2];
        for (int j = 0; j < bytes.length; j++) {
            int v = bytes[j] & 0xFF;
            hexChars[j * 2] = hexArray[v >>> 4];
            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
        }
        return new String(hexChars);
    }
}

Related

  1. bytesToHexChars(byte[] bytes)
  2. bytesToHexChars(byte[] bytes)
  3. bytesToHexChars(byte[] bytes)
  4. bytesToHexChecksum(byte[] byteArr)
  5. bytesToHexDelimeter(byte[] data, String delimeter)
  6. bytesToHexSpaced(byte[] bytes)
  7. bytesToHexStr(byte[] bcd)
  8. bytesToHexStr(byte[] bytes)
  9. bytesToHexStr(byte[] bytes, int offset, int size)