Java Hex Calculate toHex(byte in[])

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

Description

to Hex

License

Open Source License

Declaration

public static String toHex(byte in[]) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String toHex(byte in[]) {

        byte ch = 0x00;
        int i = 0;

        if (in == null || in.length <= 0)
            return null;

        String pseudo[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };

        StringBuffer out = new StringBuffer(in.length * 3);

        while (i < in.length) {
            ch = (byte) (in[i] & 0xF0); // Strip off high nibble
            ch = (byte) (ch >>> 4);
            // shift the bits down
            ch = (byte) (ch & 0x0F);
            // must do this is high order bit is on!
            out.append(pseudo[ch]); // convert the nibble to a String
            // Character

            ch = (byte) (in[i] & 0x0F); // Strip off low nibble
            out.append(pseudo[ch]); // convert the nibble to a String
            // Character
            out.append(" ");
            i++;/*from  w w  w.j  a va 2  s .  c o m*/
        }

        String rslt = new String(out);

        return rslt;
    }
}

Related

  1. toHex(byte b, String prefix)
  2. toHex(byte bytes[])
  3. toHex(byte data[])
  4. toHex(byte hash[])
  5. toHex(byte in)
  6. toHex(byte in[])
  7. toHex(byte input[])
  8. toHex(byte lowByte)
  9. toHex(byte n)