Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

added flip function #694

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions list/flip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#flip


**Description** :
***flip*** is an inbuilt method of C++ STL( Standard Template Library). It flips the bits of the calling bitset. This method flips all 0’s to 1’s and all 1’s to 0’s, which means it reverse each and every bit of the calling bitset when no parameter is passed.
If a parameter is passed the flip method will flip only the nth bit for the integer n passed.


```cpp
#include <iostream>
#include <bitset>
using namespace std;
int main() {
bitset<6> bit1(string("100110"));
bitset<10> bit2(string("0100001111"));
// after applying flip() function with nothing passed as parameter it returns
cout << bit1.flip() << endl;
// after applying flip() function with 7 passed as parameter it returns
cout << bit2.flip(7);
return 0;
}
```
[See the Detail Code ](../snippets/list/flip.cpp)
21 changes: 21 additions & 0 deletions snippets/list/flip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide

/*
Author: Mithil Joshi
Date: 12/10/2022
Time: 14:40
Description: flip the bits of the calling bitset using flip().
*/

#include <iostream>
#include <bitset>
using namespace std;
int main() {
bitset<6> bit1(string("100110"));
bitset<10> bit2(string("0100001111"));
// after applying flip() function with nothing passed as parameter it returns
cout << bit1.flip() << endl;
// after applying flip() function with 7 passed as parameter it returns
cout << bit2.flip(7);
return 0;
}