-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
  • 17,727
  • 4
  • 43
  • 54
Vineet1982
  • 7,552
  • 4
  • 29
  • 64

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
  • 3,985
  • 2
  • 23
  • 37