C++ bitset

來源:互聯網
上載者:User

bitset就是可以存放二進位的容器。

對於bitset的主要操作有:


(constructor)
Construct bitset (public member function)    //構造bitset..   格式 bitset<長度>  名字
applicable operators
Bitset operators (functions)          //可以直接對bitset容器進行二進位操作,如 ^,|,~,<<,>>等等
operator[]
Access bit (public member function)  //可以用如數組形式的賦值。bitset<4> b;  b[0]=1; 
set
Set bits (public member function)//預設將容器中所有值賦為1,也可以將特定的位置賦給特定的值
如  bitset<4> b;   b.set();   //1111.    b.set(2,0)  //  1011.
reset
Reset bits (public member function) //預設將容器中所有值賦值為0,也可以將特定位置賦特定的值
flip
Flip bits (public member function)//預設將容器中的數取反,1變0,0變1,也可以將特定位置取反bitset<4> b(string ("0001"));  b.file(2);  // 0101;  b.file();
  //1010
to_ulong
Convert to unsigned long integer (public member function)   //將容器的值轉化成10進位的數
to_string
Convert to string (public member function)           //將容器累的值轉為字串
count
Count bits set (public member function)              //統計容器中1的個數
size
Return size (public member function)                  //容器的大小
test
Return bit value (public member function)           //返回每個位置上的數
any
Test if any bit is set (public member function)   //容器的值>0返回真,反之。
none
Test if no bit is set (public member function)    //和any取反。容器的值==0返回真。反之

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.