Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     * Returns the byte array as a hex string in the format
     * "0x1234".
     * @param data byte array
     * @return hex string
     */
    public static String getHexString(byte[] data) {
        StringBuffer hex = new StringBuffer("0x");
        if (data != null)
            for (int i = 0; i < data.length; i++) {
                String digit = Integer.toString(data[i] & 0x0ff, 16);
                if (digit.length() < 2)
                    hex.append('0');
                hex.append(digit);
            }
        return hex.toString();
    }
}