Reputation: 374
How does the code in java
for (int a=0; a < 256; a++) {
sta[a] = (byte)a;
System.out.println(a);
}
prints 0 to 255 when the maximum value if a byte is 127.
How to convert int to unsigned byte using "& oxff" ?
Upvotes: 0
Views: 1021
Reputation: 881
the width of byte is 8 bits while integer is 32 bits. An you can convert for example
int a = 23;
byte b = (byte)a;
Upvotes: 0
Reputation: 160
You are casting the integer variable a into a byte variable being stored in an array. However the variable you are printing is a which still is an integer.
Upvotes: 4