How to convert binary to decimal in C

1 Answer

0 votes
#include <stdio.h>

int main(void) {
    int binary = 11111101, decimal = 0, base = 1, reminder;  
  
    while (binary > 0) {  
        reminder = binary % 10; 
        decimal = decimal + reminder * base;  
        binary = binary / 10; 
        base = base * 2;  
    }  
  
    printf ("%d", decimal);   
    
    return 0;
}





/*
run:
    
253
    
*/

 

 



answered Aug 24, 2021 by avibootz
edited Aug 24, 2021 by avibootz

Related questions

1 answer 357 views
1 answer 318 views
2 answers 373 views
1 answer 290 views
2 answers 481 views
481 views asked Sep 9, 2014 by avibootz
2 answers 296 views
1 answer 220 views
220 views asked Aug 24, 2021 by avibootz
...