Bitwise Representation of Data Types
C++
Medium
5 views
Problem Description
Display binary representation of different data types. This builds understanding of how data is stored in memory.
Logic: Extract and display individual bits using bitwise operations
Official Solution
void question10_binary_representation() {
int num = 10;
cout << "Decimal: " << num << endl;
cout << "Binary: ";
for(int i = 31; i >= 0; i--) {
int bit = (num >> i) & 1;
cout << bit;
if(i % 8 == 0) cout << " ";
}
cout << endl;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!