Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Unfortunately, there are no unsigned types in Java, but it is possible to apply a bitmask to a value before deriving or using it:
public class bytes{
public static void main(String[] args){
byte b = (byte) 200;
System.out.println(b & 0xFF);
b+=100;
System.out.println(b & 0xFF);
}
}
note: if you need values from 0 to 255, then the byte type is not suitable for you. byte ranges from -128 to 127. As a result, if you need a range from 0 to 255, use short or int, or cast b to int.
The essence of the question is a little unclear: it means that if b=200, you do b += 100 and as a result you want to get 255 (a kind of protection against "overflow")? or something different?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question