Advertisement
MBrendecke

Coding Challange 6 - CPP

Aug 9th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. int main()
  5. {
  6.     while (true)
  7.     {
  8.         unsigned long long zahl = 0;
  9.         unsigned long long rev = 0;
  10.  
  11.         printf("Enter number:");
  12.         scanf_s("%lld", &zahl);
  13.  
  14.         while (zahl > 0) {
  15.             rev <<= 1;
  16.  
  17.             if ((zahl & 1) == 1) {
  18.                 rev ^= 1;
  19.             }
  20.  
  21.             zahl >>= 1;
  22.         }
  23.  
  24.         while (rev > 0)
  25.         {
  26.             printf("%d", ((rev & 1) == 1) ? 1 : 0);
  27.             rev >>= 1;
  28.         }
  29.  
  30.         printf("\n");
  31.     }
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement