Advertisement
Guest User

Cancer2.c

a guest
Dec 20th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.29 KB | None | 0 0
  1. int read_bin(){
  2.     int n;
  3.     printf("Digite Bin: ");
  4.     scanf("%d",&n);
  5.     int decimal = 0, i = 0, rem = 0;
  6.  
  7.     while(n != 0){
  8.         rem = n % 10;
  9.         if(rem == 1 || rem == 0){
  10.             n /= 10;
  11.             decimal += rem * pow(2, i);
  12.         }
  13.         else{
  14.             printf("ERRO\n");
  15.             return -1;
  16.         }
  17.     }
  18.     return decimal;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement