Java Byte Array to Hex bytesToHex(byte[] a)

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

Description

bytes To Hex

License

Open Source License

Declaration

public static String bytesToHex(byte[] a) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 BSI Business Systems Integration AG.
 * 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
 *
 * Contributors://from  ww w .  j  a v  a  2  s.c o  m
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/

public class Main {
    public static String bytesToHex(byte[] a) {
        if (a == null || a.length == 0) {
            return null;
        }
        StringBuffer buf = new StringBuffer(a.length * 2);
        int hi, lo;
        for (int i = 0; i < a.length; i++) {
            lo = (a[i]) & 0xff;
            hi = (lo >> 4);
            lo = lo & 0x0f;
            buf.append(Integer.toHexString(hi));
            buf.append(Integer.toHexString(lo));
        }
        return buf.toString();
    }
}

Related

  1. bytes2HexString(byte[] src)
  2. bytes2HexStringWithSeparator(String separator, byte... bytes)
  3. bytesToHex(byte bytes[], int offset, int length, boolean wrap)
  4. bytesToHex(byte in[])
  5. bytesToHex(byte... bytes)
  6. bytesToHex(byte[] a)
  7. bytesToHex(byte[] array)
  8. bytesToHex(byte[] b)
  9. bytesToHex(byte[] b)