zoukankan      html  css  js  c++  java
  • 10.bitset

     1 #include <iostream>
     2 //位运算,处理二进制非常方便,线性存储
     3 #include <bitset>
     4 #include <string>
     5 using namespace std;
     6 
     7 void main()
     8 {
     9     //bitset<8> mybit(255);//1111 1111
    10     //for (int i = 7; i >= 0; i--)
    11     //{
    12     //    cout << mybit[i] << endl;
    13     //}
    14     int num = -1;
    15     bitset<32> mybit(num);
    16     for (int i = 31; i >= 0; i--)
    17     {
    18         cout << mybit[i];
    19     }
    20 
    21     string strl = mybit.to_string();//转化字符串
    22     unsigned long longl = mybit.to_ulong();//转化为无符号整数
    23 
    24     cout << "str1:" << strl << endl;
    25     cout << "longl:" << longl << endl;
    26 
    27     mybit.reset();//重置
    28     mybit.set(13, 1);//设置二进制位
    29     cin.get();
    30 }
  • 相关阅读:
    C#
    C#
    C#
    python——socket网络编程
    Python——面向对象
    Python——函数
    Python——列表深浅拷贝
    Python——文件操作
    多级菜单(增强版)
    Python 编码机制
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8627176.html
Copyright © 2011-2022 走看看