C++ 中的 CHAR_BIT
CHAR_BIT 是 char 中的位数。它在 C++ 语言的“limits.h”头文件中声明。每个字节 8 位。
下面是 C++ 语言中 CHAR_BIT 的示例:
示例
#include <bits/stdc++.h>
using namespace std;
int main() {
int x = 28;
int a = CHAR_BIT*sizeof(x);
stack<bool> s;
cout << "The number is : " << x << endl;
for (int i=1; i<=a; i++) {
s.push(x%2);
x = x/2;
}
cout << "The number of bits in a byte : " << CHAR_BIT << endl;
for (int i=1; i<=a; i++) {
cout << s.top();
s.pop();
if (i % CHAR_BIT == 0)
cout << " ";
}
return 0;
}输出
The number is : 28 The number of bits in a byte : 8 00000000 00000000 00000000 00011100
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP