Java Java String Format toJavaHex(byte in[], int len)

Here you can find the source of toJavaHex(byte in[], int len)

Description

to Java Hex

License

Open Source License

Declaration

public static String toJavaHex(byte in[], int len) 

Method Source Code

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

public class Main {
    public static String toJavaHex(byte in[], int len) {

        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(len * 12);

        while (i < len) {
            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("(byte)0x");
            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++;/* w ww  . ja  v a  2s .  c om*/
        }

        String rslt = new String(out);

        return rslt;

    }
}

Related

  1. toJavaCasing(final String pName)
  2. toJavaClassName(String str)
  3. toJavaConstantIdentifier(String name)
  4. toJavadocComment(String comment)
  5. toJavaEnum(String inStr)
  6. toJavaHexCharString(final char chr)
  7. toJavaIdentifier(String name)
  8. toJavaIdentifier(String name)
  9. toJavaIdentifier(String nodeName, boolean boundary)