Android Byte Array to Hex Convert convertToHexString(byte[] b)

Here you can find the source of convertToHexString(byte[] b)

Description

convert To Hex String

License

Apache License

Declaration

private static String convertToHexString(byte[] b) 

Method Source Code

//package com.java2s;
/*//from w  w w.j av a  2  s  .com
 * Copyright (C) 2014 Qiujuer <qiujuer@live.cn>
 * WebSite http://www.qiujuer.net
 * Created 09/22/2014
 * Changed 01/14/2015
 * Version 1.0.0
 *
 * 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.
 */

public class Main {
    private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4',
            '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

    private static String convertToHexString(byte[] b) {
        StringBuilder sb = new StringBuilder(b.length * 2);
        for (byte a : b) {
            sb.append(HEX_DIGITS[(a & 0xf0) >>> 4]);
            sb.append(HEX_DIGITS[a & 0x0f]);
        }
        return sb.toString();
    }
}

Related

  1. toHexString(byte[] keyData)
  2. toHexStringArray(byte[] bytes)
  3. convertToHex(byte[] data)
  4. convertToHex(byte[] data)
  5. convertToHex(byte[] data)
  6. encodeHex(byte[] data)
  7. encodeHex(byte[] data)
  8. convertToHex(byte[] data)
  9. byteArrayToHexString(byte[] array)