Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Java Program to convert an UNSIGNED byte to a JAVA type
Firstly, let us declare byte values.
byte val1 = 127; byte val2 = -128;
To convert the above given unsigned byte, you can use the following. Here, we are first implementing it for the variable “val1”.
(int) val1 & 0xFF
Now for the second variable “val2”.
(int) val2 & 0xFF
Let us see the complete example to convert an UNSIGNED bye to a JAVA type.
Example
import java.util.*;
public class Demo {
public static void main(String[] args) {
byte val1 = 127;
byte val2 = -128;
System.out.println(val1);
System.out.println((int) val1 & 0xFF);
System.out.println(val2);
System.out.println((int) val2 & 0xFF);
}
}
Output
127 127 -128 128
Advertisements
