Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4.  
  5. int main(int argc, char* argv[])
  6. {
  7. int32_t numberInput = 0;
  8. uint32_t numberMask = (1 << 31); //43690%
  9. uint32_t numberFinal = 0;
  10.  
  11. while (true)
  12. {
  13. numberMask = (1U << 31);
  14. printf("Please enter a number to translate into binary\nTo Exit please type the number 9999\n");
  15. scanf("%d", &numberInput);
  16. numberFinal = (uint32_t)numberInput;
  17.  
  18. if (numberFinal == 9999)
  19. {
  20. break;
  21. }
  22. else
  23. {
  24. for (int i = 0; i < 32; i++)
  25. {
  26. bool isOne = (numberMask & numberFinal) != 0;
  27. printf("%d", (isOne) ? 1 : 0);
  28. numberMask >>= 1;
  29. }
  30. printf("\n\n");
  31. }
  32.  
  33.  
  34. }
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement