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

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

Description

bytes To Hex String

License

Open Source License

Declaration

public static String bytesToHexString(byte[] bytes) 

Method Source Code

//package com.java2s;
/*//  ww w.j a  va  2s  . co  m
 * Copyright (c) 2015 Yoyodyne, Inc. 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 {
    public static String bytesToHexString(byte[] bytes) {

        if (bytes == null) {
            return "null";
        }

        String ret = "";
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < bytes.length; i++) {
            if (i > 0) {
                ret += ":";
            }
            short u8byte = (short) (bytes[i] & 0xff);
            String tmp = Integer.toHexString(u8byte);
            if (tmp.length() == 1) {
                buf.append("0");
            }
            buf.append(tmp);
        }
        ret = buf.toString();
        return ret;
    }
}

Related

  1. bytesToHexString(byte[] bArray)
  2. bytesToHexString(byte[] bs)
  3. bytesToHexString(byte[] buf)
  4. bytesToHexString(byte[] byteArray)
  5. bytesToHexString(byte[] bytes)
  6. bytesToHexString(byte[] bytes)
  7. bytesToHexString(byte[] bytes)
  8. bytesToHexString(byte[] bytes)
  9. bytesToHexString(byte[] bytes)