Reputation: 881
I am trying to preform a simple bitwise statement to see if a user has security. It seems to be ok until i introduce variables.
This Works: byte test = 1 & 3.
Won't work: byte a = 1; byte b = 3; byte test = a & b;
Is there anyway that I can get this to work?
Upvotes: 1
Views: 173
Reputation: 34846
You need to cast it back to a byte
as a bitwise AND will return an int
, so do this:
byte a = 1;
byte b = 3;
byte test = (byte)(a & b);
Upvotes: 4