-1

Today I am understanding the header files of Linux Cross Platform while reading on here written code on specific lin

#define _bnd(X, bnd)            (((sizeof (X)) + (bnd)) & (~(bnd)))

I want to know what does (~) sign do. I have not found any documentation regarding this character anywhere.

Dexter
  • 18,213
  • 4
  • 44
  • 54
Vineet1982
  • 7,730
  • 4
  • 32
  • 67

1 Answers1

2

The ~ operator is the bitwise not operator. This will make all the binary ones in a number zero and all the zeros will become ones.

You can consider the ~ operator as a way of inverting a binary number. For example, when you are using flags, the ~ operator will turn off all flags that were previously on and vice versa.

Mathematically, the ~ operator is one less than the twos-complement of a number.

So, using a concrete example:

Let a = 1010 (binary)
Then ~a = 0101 (binary)
ose
  • 4,065
  • 2
  • 24
  • 40