Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
C Program: Print Binary Representation of a Number
✅ C Program: Binary Representation of a Number
#include<stdio.h>
int main( )
{
unsigned int num;
printf("Enter the number:\n");
scanf("%u", &num);
for(int i = 31; i >= 0; i--)
{
if(num & (1 << i))
printf("1");
else
printf("0");
}
printf("\n");
}
๐ Explanation:
This program prints the binary representation of an unsigned integer using bitwise operators.
- The user inputs a number.
- The loop checks all 32 bits (from MSB to LSB).
- If the bit is set, it prints
1; otherwise,0. - This uses the expression
(num & (1 << i))to test each bit.
๐งพ Sample Output:
Enter the number: 5 00000000000000000000000000000101
๐ Keywords:
C Program, Binary in C, Bitwise Operator in C, Binary Print, 32-bit Output, C Interview Questions, Unsigned Integer Handling
๐ Hashtags:
#CProgramming #BitwiseOperators #BinaryOutput #InterviewPreparation #AdSenseReady #CodingBlog
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment