Here you can find the source of toHexString(byte[] v)
Parameter | Description |
---|---|
v | a parameter |
public static String toHexString(byte[] v)
//package com.java2s; /*/* w w w . j a v a2s . c o m*/ * Copyright (c) 2003-2012 Fred Hutchinson Cancer Research Center * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Convert a byte array to a hex string * @param v * @return */ public static String toHexString(byte[] v) { StringBuffer sb = new StringBuffer(); byte n1, n2; for (int c = 0; c < v.length; c++) { n1 = (byte) ((v[c] < 0 ? -v[c] + 127 : v[c]) / 0x10); n2 = (byte) ((v[c] < 0 ? -v[c] + 127 : v[c]) % 0x10); sb.append(n1 >= 0xA ? (char) (n1 - 0xA + 'a') : (char) (n1 + '0')); sb.append(n2 >= 0xA ? (char) (n2 - 0xA + 'a') : (char) (n2 + '0')); } return sb.toString(); } }