Here you can find the source of toHexString(byte[] binaryData)
Parameter | Description |
---|---|
binaryData | the data, may be null |
public static String toHexString(byte[] binaryData)
//package com.java2s; /**/* w w w. j a v a 2s . co m*/ * Tentackle - a framework for java desktop applications * Copyright (C) 2001-2008 Harald Krake, harald@krake.de, +49 7722 9508-0 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ public class Main { private static final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /** * Creates a human-readable hex-String out of a byte-array (e.g. from MessageDigest MD5sum). * * @param binaryData the data, may be null * @return the formatted hex string , null if data was null */ public static String toHexString(byte[] binaryData) { if (binaryData != null) { char[] text = new char[binaryData.length << 1]; int j = 0; byte b; for (int i = 0; i < binaryData.length; ++i) { b = binaryData[i]; text[j++] = hexDigits[(b & 0xf0) >> 4]; text[j++] = hexDigits[b & 0x0f]; } return new String(text); } return null; } }