Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Transforms bytes to String
     *
     * @param data bytes
     * @return String
     */
    public static String bytesToHex(byte[] data) {
        if (data == null)
            return null;

        String str = "";
        for (byte aData : data) {
            if ((aData & 0xFF) < 16)
                str = str + "0" + Integer.toHexString(aData & 0xFF);
            else
                str = str + Integer.toHexString(aData & 0xFF);
        }
        return str;
    }
}