zoukankan      html  css  js  c++  java
  • 位集合学习代码

     

    #include<iostream>
    #include<bitset>
    using namespace std;
    void display(bitset<8> bs)
    {
     cout<<"Bitset=";
     for(int x=0;x<8;++x)
      cout<<bs[x];
     cout<<endl;
    }

    int main()
    {
     bitset<8> MybitSet;
     MybitSet.set(1);
     MybitSet.set(2);
     MybitSet.set(3);
     MybitSet.set(5);
     MybitSet.set(7);
     display(MybitSet);
     for(int x=0;x<8;++x)
     {
      cout<<"Bit"<<x<<" is ";
      if(MybitSet.test (x))
       cout<<"set";
      else
       cout<<"unset";
      cout<<endl;
     }

     return 0;
    }
    /*运行结果如下:
    Bitset=01110101
    Bit0 is unset
    Bit1 is set
    Bit2 is set
    Bit3 is set
    Bit4 is unset
    Bit5 is set
    Bit6 is unset
    Bit7 is set
    Press any key to continue
    */

  • 相关阅读:
    数组迭代方法
    promise
    Gulp执行预处理
    第一个gulp 项目
    vue 单元素过渡
    webpack 入门
    webpack初始化
    v-for 指令
    ajax 工作原理
    面试小问题
  • 原文地址:https://www.cnblogs.com/feng801/p/1291457.html
Copyright © 2011-2022 走看看