Here you can find the source of toHex(final byte[] bytes)
Parameter | Description |
---|---|
bytes | The bytes to convert. |
public static String toHex(final byte[] bytes)
//package com.java2s; /*//from w w w . j av a 2 s . c o m * #%L * IOUtils.java - mongodb-async-driver - Allanbank Consulting, Inc. * %% * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc. * %% * 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. * #L% */ public class Main { /** Hex encoding characters. */ private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); /** * Converts the byte array into a HEX string. * * @param bytes * The bytes to convert. * @return The string version. */ public static String toHex(final byte[] bytes) { final StringBuilder builder = new StringBuilder(bytes.length * 2); for (final byte b : bytes) { builder.append(HEX_CHARS[(b >> 4) & 0xF]); builder.append(HEX_CHARS[b & 0xF]); } return builder.toString(); } }