A byte is always signed in Java. You may get its unsigned value by binary-anding it with 0xFF, though:
int i = 234;
byte b = (byte) i;
System.out.println(b); // -22
int i2 = b & 0xFF;
System.out.println(i2); // 234
More Related Contents:
- How are integers cast to bytes in Java?
- How to convert a Byte Array to an Int Array
- Convert a string representation of a hex dump to a byte array using Java?
- Determine if a String is an Integer in Java [duplicate]
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- Java: parse int value from a char
- Java Byte Array to String to Byte Array
- Java Array Sort descending?
- Convert integer into byte array (Java)
- How do I convert Long to byte[] and back in java
- Convert boolean to int in Java
- In Java 8, is there a ByteStream class?
- Java int to String – Integer.toString(i) vs new Integer(i).toString()
- What does an integer that has zero in front of it mean and how can I print it?
- Is it valid to compare a double with an int in java?
- Splitting String and put it on int array
- Convert binary string to byte array
- Set specific bit in byte
- How to convert hex strings to byte values in Java
- Java: why do I receive the error message “Type mismatch: cannot convert int to byte”
- Convert short to byte[] in Java
- How can I convert a char to int in Java? [duplicate]
- Adding char and int
- Why does the xor operator on two bytes produce an int?
- Why is Java able to store 0xff000000 as an int?
- Can assign integer value to char but can’t assign integer variable to char
- How to convert byte[] to Byte[] and the other way around?
- Dividing two integers to a double in java
- Searching for a sequence of Bytes in a Binary File with Java
- Using int vs Integer