Invert bits in a UShort

  • Thread starter Thread starter Peter Aitken
  • Start date Start date
P

Peter Aitken

I want to invert all the bits (all 0s to 1s, all 1s to 0s) in a type
ushort. I though I would use the complement operator ~ but the compiler
won't buy it. How can I do this?

Thanks,
 
Peter Aitken said:
I want to invert all the bits (all 0s to 1s, all 1s to 0s) in a type
ushort. I though I would use the complement operator ~ but the compiler
won't buy it. How can I do this?

Is this what you want:
ushort u1 = 55;
ushort u2 = (ushort) ~u1;
 
Back
Top