Reputation: 505
see example below. I was either expecting it to be 1 or 249 if we account for the whole bits in the byte type.
I read the sources but I can't figure out why I am not able to grasp it.
byte num1 = 6;
byte num2 = 12;
Assert.IsTrue(~num1 == 1);
Assert.IsTrue(~num2 == 3);
Upvotes: 0
Views: 88
Reputation: 24903
~
operator converts type to int
. If you want byte
- use cast:
byte num1 = 6;
byte num2 = 12;
Console.WriteLine((byte)~num1);
Console.WriteLine((byte)~num2);
Upvotes: 2