Java Hex Calculate toHex(byte[] dBytes)

Here you can find the source of toHex(byte[] dBytes)

Description

to Hex

License

Apache License

Declaration

private static String toHex(byte[] dBytes) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private static String toHex(byte[] dBytes) {
        char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'A', 'B', 'C', 'D', 'E', 'F' };
        StringBuffer back = new StringBuffer();

        for (int i = 0; i < dBytes.length; ++i) {
            int d = dBytes[i];

            if (d < 0) {
                d = 256 + d;/*ww w  .  jav a 2  s  .  co m*/
            }

            int a = d / 16;
            int c = d % 16;
            back.append(hex[a]).append(hex[c]);
        }

        return back.toString();
    }
}

Related

  1. toHex(byte[] data)
  2. toHex(byte[] data, int bytesPerGroup)
  3. toHex(byte[] data, int length)
  4. toHex(byte[] data, int off, int len)
  5. toHex(byte[] data, int perLine, boolean offset)
  6. toHex(byte[] digest)
  7. toHex(byte[] digest)
  8. toHex(byte[] inBytes)
  9. toHex(byte[] input)