Here you can find the source of bytesToHexStr(byte[] bytes, int offset, int size)
Parameter | Description |
---|---|
bytes | a parameter |
offset | a parameter |
size | a parameter |
public static String bytesToHexStr(byte[] bytes, int offset, int size)
//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); } }