Here you can find the source of toHex(byte[] buffer)
Parameter | Description |
---|---|
buffer | array of bytes to convert |
private static String toHex(byte[] buffer)
//package com.java2s; /* 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.//from w w w.j a v a2 s .c om */ public class Main { /** * Converts an array of bytes into a String representing each byte as an * unsigned hex number. * * @param buffer array of bytes to convert * @return generated hex string */ private static String toHex(byte[] buffer) { StringBuffer sb = new StringBuffer(); String s = null; for (int i = 0; i < buffer.length; i++) { s = Integer.toHexString((int) buffer[i] & 0xff); if (s.length() < 2) { sb.append('0'); } sb.append(s); } return sb.toString(); } }