Arduino Programming Language: BitwiseXorNot

Name

~ (Bitwise NOT)

Description

The bitwise NOT operator is the tilde character ~. Unlike & and |, the bitwise NOT operator is applied to a single operand to its right. Bitwise NOT changes each bit to its opposite: 0 becomes 1, and 1 becomes 0.

Syntax

~expression

Parameters

expression: any valid expression

Returns

One's complement of an expression

Usage

Application

Note

You might be surprised to see a negative number. This is because the highest bit in an int variable is the so-called sign bit. If the highest bit is 1, the number is interpreted as negative. This encoding of positive and negative numbers is referred to as two's complement.