bitset::flip() is a built-in STL in C++ which flips the bits. If no parameter is passed in the function, then it flips all the bit values converting zeros to ones and ones to zeros. If a parameter position is passed, it flips the bit at the position only.
Parameter: The function accepts a parameter pos which is not mandatory. If a parameter pos is passed, it flips the bit at the index pos only(the index pos is calculated starting from the right). In case no parameter is passed, it flips all the bit values converting zeros to ones and ones to zeros.
Return Value: The function flips all the bit values according to the parameter passed or not and returns the new binary representation of the number.
Below programs illustrates the bitset::flip() function.
0011 after applying flip() function returns 0011 101101 after applying flip() function returns 101101
0100 after applying flip(3) function returns 0100 1100100 after applying flip(6) function returns 1100100
- Generate a random permutation of elements from range [L, R] (Divide and Conquer)
- Passing and Returning Objects in C++
- Train a Support Vector Machine to recognize facial features in C++
- Salesforce Interview Experience | On-Campus for FTE
- unordered_set operators in C++ STL
- Dividing a Large file into Separate Modules in C/C++, Java and Python
- How to delete a range of values from the List using Iterator
- How to create a List with Constructor in C++ STL
- How to delete last element from a List in C++ STL
- Can C++ reference member be declared without being initialized with declaration?
- Finding Floor and Ceil of a Sorted Array using C++ STL
- Some useful C++ tricks for beginners in Competitive Programming
- Replace each node with its Surpasser Count in Linked List
- Comparison of Java with other programming languages
- Print multiples of Unit Digit of Given Number