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

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

Description

bytes To Hex String

License

Open Source License

Declaration

private static String bytesToHexString(byte data[]) 

Method Source Code

//package com.java2s;
/*//from   w  w  w  .j  av a  2  s  .c o  m
 *  Copyright (C) 2008  John-Paul.Stanford <dev@stanwood.org.uk>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    private final static char HEX_DIGITS[] = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
            'b', 'c', 'd', 'e', 'f' };

    private static String bytesToHexString(byte data[]) {

        StringBuilder sb = new StringBuilder(data.length * 2);
        for (int buc = 0; buc < data.length; buc++) {
            sb.append(HEX_DIGITS[(data[buc] >> 4) & 0x0F]);
            sb.append(HEX_DIGITS[data[buc] & 0x0F]);
        }

        return sb.toString();
    }
}

Related

  1. bytesToHexStr(byte[] bytes)
  2. bytesToHexStr(byte[] bytes, int offset, int size)
  3. bytesToHexString(byte abyte0[])
  4. bytesToHexString(byte abyte0[], int i, int j)
  5. bytesToHexString(byte bytes[])
  6. bytesToHexString(byte[] _bytes)
  7. bytesToHexString(byte[] array)
  8. bytesToHexString(byte[] b)
  9. bytesToHexString(byte[] b, int length)