C++输出二进制数
示例
#include<windows.h> #include<sstream> #include<atlstr.h> #include<bitset> using namespace std;int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) {DWORD dword = GetLogicalDrives();stringstream str;str << bitset<32>(dword);string str1;str >> str1;CString out = str1.c_str();MessageBox(NULL, out, L"輸出", MB_OK);return 0; }使用 bitset 可以很方便的輸出二進制數。要包含頭文件 bitset
#include<bitset>語法
int a; cout << bitset<32>(a);尖括號里的數字為二進制數的位數
bitset的定義如下
constexpr bitset(unsigned long long _Val) noexcept : _Array{static_cast<_Ty>(_Need_mask ? _Val & _Mask : _Val)} {}簡書上一個網友說得挺好的
總結
- 上一篇: 保存文件 everyone 权限
- 下一篇: 数模2021暑期培训