Java Byte Array to Hex bytesToHex(byte[] b)

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

Description

bytes To Hex

License

Apache License

Declaration

public static String bytesToHex(byte[] b) 

Method Source Code

//package com.java2s;
//   Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    private static final String HEX = "0123456789ABCDEF";

    public static String bytesToHex(byte[] b) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < b.length; i++) {
            sb.append(byteToHex(b[i])).append(" ");
        }//from   w  w  w . j a  va  2 s  .co m
        return sb.toString();
    }

    public static String byteToHex(byte b) {
        int high = (b & 0xF0) >> 4;
        int low = (b & 0x0F);

        return "" + HEX.charAt(high) + HEX.charAt(low);
    }
}

Related

  1. bytesToHex(byte[] a)
  2. bytesToHex(byte[] array)
  3. bytesToHex(byte[] b)
  4. bytesToHex(byte[] b)
  5. bytesToHex(byte[] b)
  6. bytesToHex(byte[] b, int offset, int length)
  7. bytesToHex(byte[] binary)
  8. bytesToHex(byte[] bs, int off, int length)
  9. bytesToHex(byte[] bt)