Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Convert byte to Hex String
     * 
     * @param b
     *            the byte to be converted
     * @return the Hex String
     */
    public static String convertByte2HexString(byte b) {
        char u8 = convertByte2Uint8(b);
        return Integer.toHexString(u8);
    }

    /**
     * Convert char into uint8( we treat char as uint8 )
     * 
     * @param b
     *            the byte to be converted
     * @return the char(uint8)
     */
    public static char convertByte2Uint8(byte b) {
        // char will be promoted to int for char don't support & operator
        // & 0xff could make negatvie value to positive
        return (char) (b & 0xff);
    }
}