Here you can find the source of byteArrayToHexString(byte[] bytes, int pos, int len)
Parameter | Description |
---|---|
bytes | a byte array. |
pos | the start position |
len | number of bytes to be converted |
public static String byteArrayToHexString(byte[] bytes, int pos, int len)
//package com.java2s; /**//from ww w. j a v a2 s. co m * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ import java.util.Formatter; public class Main { /** * Converts a byte array to hex string. * * @param bytes a byte array. * @param pos the start position * @param len number of bytes to be converted * @return hex string. */ public static String byteArrayToHexString(byte[] bytes, int pos, int len) { StringBuilder sb = new StringBuilder(bytes.length * 2); Formatter formatter = new Formatter(sb); for (int i = pos; i < pos + len; ++i) { formatter.format("%02x", bytes[i]); } return sb.toString(); } }