C Online Compiler
Example: C program to convert decimal to binary using bitwise operator
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C program to convert decimal to binary using bitwise operator #include <stdio.h> // The main function of the program int main() { // Step-1 Declare variables int num, i; // Step-2 Input a decimal number from the user printf("Enter a decimal number: "); scanf("%d", &num); // Step-3 Display binary representation using bitwise operations printf("Binary representation: "); for(i = 31; i >= 0; i--) { // Extract i-th bit from the left int bit = (num >> i) & 1; printf("%d", bit); } printf("\n"); return 0; }
5
Output
Clear
ADVERTISEMENTS