During any calculations any number higher than 255 is set to 255.
This is not supported natively in C#. Instead, the default behaviour of the (byte)
cast is to take the least significant byte, giving an arithmetic result equivalent to modulo 256.
c = unchecked((byte)(200 + 200));
The result above will be 144
, which is equivalent to 400 % 256
.
If you want to clip results at 255, you need to specify this explicitly:
c = (byte)Math.Min(a + b, 255);