Java Byte Array to Hex String bytesToHexStr(byte[] bytes, int offset, int size)

Here you can find the source of bytesToHexStr(byte[] bytes, int offset, int size)

Description

bytes To Hex Str

License

Open Source License

Parameter

Parameter Description
bytes a parameter
offset a parameter
size a parameter

Declaration

public static String bytesToHexStr(byte[] bytes, int offset, int size) 

Method Source Code

//package com.java2s;
/*//from   ww  w . jav a 2 s.c  o  m
 * This file is part of trolCommander, http://www.trolsoft.ru/soft/trolcommander
 * Copyright (C) 2013-2014 Oleg Trifonov
 *
 * muCommander 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.
 *
 * muCommander 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 static final char[] HEX_CHAR_ARRAY = "0123456789ABCDEF".toCharArray();

    /**
     *
     * @param bytes
     * @param offset
     * @param size
     * @return
     */
    public static String bytesToHexStr(byte[] bytes, int offset, int size) {
        char[] hexChars = new char[size * 2];
        for (int i = offset; i < offset + size; i++) {
            int v = bytes[i] & 0xFF;
            hexChars[i * 2] = HEX_CHAR_ARRAY[v >>> 4];
            hexChars[i * 2 + 1] = HEX_CHAR_ARRAY[v & 0x0F];
        }
        return new String(hexChars);
    }
}

Related

  1. bytesToHexDelimeter(byte[] data, String delimeter)
  2. bytesToHexFormatted(byte[] bytes)
  3. bytesToHexSpaced(byte[] bytes)
  4. bytesToHexStr(byte[] bcd)
  5. bytesToHexStr(byte[] bytes)
  6. bytesToHexString(byte abyte0[])
  7. bytesToHexString(byte abyte0[], int i, int j)
  8. bytesToHexString(byte bytes[])
  9. bytesToHexString(byte data[])