Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. int binary_to_decimal(char bin[]){
  2.  
  3. int index, sum;
  4. int accumulator = 64;
  5.  
  6. for(index = 0; index < 8; index++) {
  7. if(accumulator > 0){
  8. if(bin[index] == '1'){
  9. sum = sum + accumulator;
  10. accumulator = accumulator / 2;
  11. }
  12. else
  13. accumulator = accumulator / 2;
  14. }
  15.  
  16.  
  17. }
  18. printf("Num: %d", sum);
  19.  
  20.  
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement