Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    static String HexForBytes(byte[] bytes) {
        StringBuffer sb = new StringBuffer();
        for (byte b : bytes)
            sb.append(HexForByte(b));
        return sb.toString();
    }

    static String HexForByte(byte b) {
        String Hex = Integer.toHexString((int) b & 0xff);
        boolean hasTwoDigits = (2 == Hex.length());
        if (hasTwoDigits)
            return Hex;
        else
            return "0" + Hex;
    }
}