CHAR_BIT in C Last Updated : 27 May, 2022 Comments Improve Suggest changes Like Article Like Report CHAR_BIT : It is the number of bits in char. These days, almost all architectures use 8 bits per byte (But it is not the case always, some older machines used to have 7-bit byte). It can be found in Let us see an application of it. Suppose we wish to print byte by byte representation of an integer. Examples : Input : 4 Output : 00000000 00000000 00000000 00000100 Input : 12 Output : 00000000 00000000 00000000 00001100 CPP // CPP program to print byte by byte presentation #include <bits/stdc++.h> using namespace std; // function in which number and initially 0 is passed void printInBinary(int num) { int n = CHAR_BIT*sizeof(num); stack<bool> s; for (int i=1; i<=n; i++) { s.push(num%2); num = num/2; } for (int i=1; i<=n; i++) { cout << s.top(); s.pop(); // Put a space after every byte. if (i % CHAR_BIT == 0) cout << " "; } } int main() { int num = 12; printInBinary(num); return 0; } Output : 00000000 00000000 00000000 00001100 Time Complexity : O(32) Auxiliary Space : O(32) Comment More infoAdvertise with us Next Article CHAR_BIT in C A Apurva Agarwal Improve Article Tags : C Language Similar Reads Extract bits in C In C programming, extracting a bit means retrieving the value (0 or 1) of a bit or a group of bits present at a specific position in the binary representation of a numberIn this article, we will learn how to extract a bit or multiple bits at given positions in a binary number. We will also explore h 3 min read Bit Fields in C In C, we can specify the size (in bits) of the structure and union members. The idea of bit-field is to use memory efficiently when we know that the value of a field or group of fields will never exceed a limit or is within a small range. C Bit fields are used when the storage of our program is limi 8 min read Character Arithmetic in C As already known character range is between -128 to 127 or 0 to 255. This point has to be kept in mind while doing character arithmetic. What is Character Arithmetic?Character arithmetic is used to implement arithmetic operations like addition, subtraction, multiplication, and division on characters 2 min read Setting Bits in C In C programming, setting a bit is the process of setting a specific bit of a binary number to 1. This operation is crucial in various applications, including memory management, data processing, and hardware control.In this article, we will learn how to set a bit at a given position in a binary numb 3 min read Counting Set bit in C In C programming, counting set bits is the process of determining the number of bits that are set to 1 in a binary number. This operation is useful in various applications including network programming, error detection, and cryptography.In this article, we will learn how to count the number of set b 4 min read Like