Flipping Bits with the Logical NOT Operator - CSharp Language Basics

CSharp examples for Language Basics:Operator

Introduction

The logical NOT operator (~) is used to flip the bits of a value.

The NOT operator is unary-it works with only one value.

The results are as follows:

  • If the bit's value is 1, the result is 0.
  • If the bit's value is 0, the result is 1.

Using this on an unsigned byte that contains the value of 1 (00000001) would result in the number 254 (11111110).


Related Tutorials