Here you can find the source of convertToHexString(byte[] input)
Parameter | Description |
---|---|
input | The byte array to convert |
public static String convertToHexString(byte[] input)
//package com.java2s; /*//from w w w.j a v a 2s .c o m * Copyright 2013 Kevin Quan (kevin.quan@gmail.com) * * 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. */ import java.util.Locale; public class Main { /** * Converts a byte array into a hexadecimal string. The string will always be lowercase. * @param input The byte array to convert * @return The hexadecimal version of the byte array */ public static String convertToHexString(byte[] input) { if (input == null || input.length == 0) { return new String(); } // From http://stackoverflow.com/a/13006907/1339200 StringBuilder sb = new StringBuilder(); for (byte b : input) { sb.append(String.format(Locale.ENGLISH, "%02x", b & 0xff)); } return sb.toString().toLowerCase(Locale.ENGLISH); } }