Here you can find the source of bytesToHexString(byte[] b, int length)
Parameter | Description |
---|---|
b | the source buffer. |
static String bytesToHexString(byte[] b, int length)
//package com.java2s; /*//w ww .ja v a 2 s .com * Microsoft JDBC Driver for SQL Server * * Copyright(c) Microsoft Corporation All rights reserved. * * This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information. */ public class Main { final static char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /** * Converts byte array to a string representation of hex bytes. * * @param b * the source buffer. * @return "hexized" string representation of bytes. */ static String bytesToHexString(byte[] b, int length) { StringBuilder sb = new StringBuilder(length * 2); for (int i = 0; i < length; i++) { int hexVal = b[i] & 0xFF; sb.append(hexChars[(hexVal & 0xF0) >> 4]); sb.append(hexChars[(hexVal & 0x0F)]); } return sb.toString(); } }