Java Hex Calculate toHexString(final byte[] bs)

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

Description

to Hex String

License

Apache License

Declaration

public static String toHexString(final byte[] bs) 

Method Source Code

//package com.java2s;
/*//w  ww .j  a v  a2  s . c  om
 * Copyright (c) 2016 yunmle.com(????????).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */

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

    public static String toHexString(final byte[] bs) {
        final int len;
        if (bs != null && (len = bs.length) != 0) {
            final char[] cs = new char[len << 1];
            final char[] myDigits = DIGITS;
            byte b;
            for (int i = 0, j = 0; i < len; i++) {
                cs[j++] = myDigits[((b = bs[i]) >>> 4) & 0xF];
                cs[j++] = myDigits[b & 0xF];
            }
            return String.valueOf(cs);
        }
        return null;
    }
}

Related

  1. toHexString(final byte hex)
  2. toHexString(final byte value)
  3. toHexString(final byte[] arr)
  4. toHexString(final byte[] array)
  5. toHexString(final byte[] b)
  6. toHexString(final byte[] bs, final char[] myDigits)
  7. toHexString(final byte[] buffer)
  8. toHexString(final byte[] bytes)
  9. toHexString(final byte[] bytes)