C++ Standard Library C++ STL Library

C++ <bitset> - operator~ Function



The C++ bitset::operator~ function is used to perform bitwise NOT operation on the given bitset object.

Syntax

bitset operator~() const;
bitset operator~() const noexcept;

Parameters

No parameter is required.

Return Value

*this

Exception

Never throws exceptions.

Example:

In the example below, the bitset::operator~ function is used to perform bitwise NOT operation on the given bitset.

#include <iostream>
#include <bitset>
using namespace std;
 
int main (){
  bitset<4> bset("1001");

  cout<<"bset is: "<<bset;

  //performing bitwise NOT operation on bset
  cout<<"\n(~bset): "<<~bset;

  return 0;
}

The output of the above code will be:

bset is: 1001
(~bset): 0110

❮ C++ <bitset> Library