Turn from this person's blog
#include <bister>
Using Std::bitset;
A word definition: A customizable number of bits that can be used as the data type of a binary record.
One, define and initialize
Bitset<n> b; B has n bits, each of which is 0;
Bitset<n> b (U); B is a copy of the unsigned long type U
Bitset<n> b (s); B is a copy of the string object s that contains n-bit strings
Bitset<n> B (S, POS, n); B is a copy of n locations in s that start at the POS position
Bitset<n> b (S,pos); B starts from the POS position of S to the end of S (the value of the note starts at the right end of B)
Note: The number of bits defined by ①n is populated with initial values at initialization, the range of assignments exceeds, and the spare is filled with 0.
②bitset reads a bit set from a string object in a right-to-left order.
Two, operation
B.any (); Does finding B exist in 1?
B.none (); There is no 1 in B?
B.count (); Number of 1 in B
B.size (); The number of bits in B
B[pos]; Accessing the value at POS in B
B.test (POS); Detects if POS is 1 in b
B.set (); Put all positions in B at 1
B.set (POS); Put the POS position in B to 1
B.reset (); Put all positions in B at 0
B.reset (POS); Put the POS position in B to 0
B.flip (); All bits in B are reversed
B.flip (POS); B in the POS at the bits counter
B.to_ulong; Returns a unsigned Long value
OS << b; Put the B-bit set output
C + + standard library Bitset type (simple use method)