Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
CHAR_BIT in C++
The CHAR_BIT is the number of bits in char. It is declared in “limits.h” header file in C++ language. It is of 8-bits per byte.
Here is an example of CHAR_BIT in C++ language,
Example
#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;
}
Output
The number is : 28 The number of bits in a byte : 8 00000000 00000000 00000000 00011100
Advertisements