Converts a unsigned byte to an signed int value. - Java java.lang

Java examples for java.lang:byte Array Convert

Description

Converts a unsigned byte to an signed int value.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte b = 2;
        System.out.println(byteToInt(b));
    }/* w w  w.  j  a va 2 s  .  c om*/

    /**
     * Converts a unsigned byte to an signed int value.
     *
     * @param b a byte
     * @return the byte as int value
     */
    public static int byteToInt(byte b) {
        return (int) b & 0x00000000FF;
    }
}

Related Tutorials