- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- Related Articles
- Convert byte primitive type to Byte object in Java
- Java Program to get the value stored in a byte as an unsigned integer
- Java Program to convert byte to string
- Java Program to convert string to byte
- Java Program to convert byte[] array to String
- Java Program to convert String to byte array
- Java program to convert Byte array to IP Address
- How to convert an object to byte array in java?
- Convert byte to String in Java
- Convert a byte to hexadecimal equivalent in Java
- How to convert an input stream to byte array in java?
- Convert a String to a byte number in Java
- Java Program to convert a Primitive Type Value to a String
- Java Program to convert a String to a float type Number
- Java Program to Convert contents of a file to byte array and Vice-Versa

Advertisements