Convert an unsigned byte to an int - Java java.lang

Java examples for java.lang:byte Array Convert

Description

Convert an unsigned byte to an int

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte b = 2;
        System.out.println(unsignedByteToInt(b));
    }//from www .  j  a v a2  s. c  om

    /**
     * Convert an unsigned byte to an int
     */
    public static int unsignedByteToInt(byte b) {
        return (int) b & 0xFF;
    }
}

Related Tutorials