-1

I would like to flip all the bits in a byte. How would I do that?

Ex:

input:  10101000
output: 01010111
SoluableNonagon
  • 11,541
  • 11
  • 53
  • 98

1 Answers1

4

Use the ~ bitwise complement operator.

byte flipped = (byte) ~original;
rgettman
  • 176,041
  • 30
  • 275
  • 357