Advertisement
Sierra_ONE

Conversion: Binary to Decimal

Sep 17th, 2023 (edited)
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.35 KB | Source Code | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void){
  4.  
  5.     int decimal,binary,position;
  6.    
  7.     //binary = 11000;
  8.     position = 1;
  9.     decimal = 0;
  10.    
  11.     printf("Enter binary number: ");
  12.     scanf("%d",&binary);
  13.    
  14.     while (binary > 0){
  15.         decimal += (binary % 10) * position;
  16.         binary /= 10;
  17.         position *= 2;
  18.     }
  19.  
  20.     printf("Decimal Equivalent: %d",decimal);
  21.    
  22.    
  23.    
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement