Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String getHexString2(final byte[] b) {
        StringBuilder result = new StringBuilder();
        for (byte element : b) {
            int asInt = unsignedByteToInt(element);
            result.append(Integer.toHexString(asInt));
        }
        return result.toString();
    }

    /**
     * Drop the sign bits in a byte for conversion to an int.
     * 
     * @param b
     *            <code>byte</code> to be converted to an int.
     * @return <code>int</code> which is the equivilant of the unsigned version
     *         of the <code>byte</code> param.
     */
    public static int unsignedByteToInt(final byte b) {
        return b & 0xFF;
    }
}