浅谈bitset

维护二进制的数据结构,常数可近似看作\(\frac{1}{32}\)

定义

bitset<4> bitset1; 长度为4,下标[0,3],默认为0

bitset<4> bitset1(x); x十进制转二进制后,取末尾4位

string s="100101";

bitset<4> bitset1(s); string直接赋值,取末尾4位

输出

bitset<4> bitset1(15); //1111

cout<<bitset1; 输出1111

bitset<4> bitset1(15);

cout<<(bitset1<<1); 输出1110

常用函数

冷门函数

B._Find_first() //查询第一个为1的位置

B._Find_next(5) //查询第五位后第一个为1的位置

转载于:https://www.cnblogs.com/y2823774827y/p/11573440.html