Java Hex Calculate toHexString(byte[] bytes)

Here you can find the source of toHexString(byte[] bytes)

Description

to Hex String

License

MIT License

Declaration

public static String toHexString(byte[] bytes) 

Method Source Code

//package com.java2s;
// Released under the MIT license ( http://opensource.org/licenses/MIT )

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

    public static String toHexString(byte[] bytes) {
        int count = bytes.length;

        StringBuilder answer = new StringBuilder(count * 2);

        for (int i = 0; i < count; i++) {
            byte b = bytes[i];

            answer.append(_hexDigits[(b >> 4) & 0xf]);
            answer.append(_hexDigits[b & 0xf]);
        }/*from  w w  w  .j av a2s . c  o m*/
        return answer.toString();
    }
}

Related

  1. toHexString(byte[] bytes)
  2. toHexString(byte[] bytes)
  3. toHexString(byte[] bytes)
  4. toHexString(byte[] bytes)
  5. toHexString(byte[] bytes)
  6. toHexString(byte[] bytes)
  7. toHexString(byte[] bytes)
  8. toHexString(byte[] bytes)
  9. toHexString(byte[] bytes)