Reputation: 367
I need to send the byte 0xFF to a client, but when I do this:
byte toSend = 0b11111111;
// or
byte toSend = 0xFF;
I get a compile error sending it can't convert from int to byte.
I want to make sure I am sending a byte with all 8 bits set to 1. How can I do that in Java?
Upvotes: 1
Views: 614
Reputation: 393936
You can cast it to byte :
byte toSend = (byte)0xFF;
Forget the other part of my answer. I'm a bit sleep deprived. Actually it's -1 that is represented as 11111111. But (byte)0xFF
works just fine.
Upvotes: 2