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
Binary to Decimal Conversion in C
✅ Binary to Decimal Conversion in C
#include<stdio.h>
int main( )
{
int num, decimal = 0, remainder, j = 1;
printf("Enter binary number:\n");
scanf("%d", &num);
while(num != 0)
{
remainder = num % 10;
decimal = decimal + remainder * j;
j = j * 2;
num = num / 10;
}
printf("The decimal value is %d\n", decimal);
}
๐ Explanation:
This program converts a binary number (input as an integer) into its decimal equivalent.
- It extracts each digit (right to left) using modulus and multiplies it by powers of 2.
- The value is added to a `decimal` variable.
- `%d` is used in printf to display the result in decimal format.
๐งพ Sample Output:
Enter binary number: 1010 The decimal value is 10
๐ Keywords:
Binary to Decimal, C Program for Number Conversion, Beginner C Code, scanf printf usage, while loop example, base-2 to base-10
๐ Hashtags:
#CProgramming #BinaryToDecimal #BeginnerCode #NumberConversion #whileLoop #scanf #printf #LogicInC
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