staafl

problem 5 - we all love bits

Mar 30th, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main()
  6. {
  7. int n = int.Parse(Console.ReadLine());
  8. for (int i = 0; i < n; i++)
  9. {
  10. int p = int.Parse(Console.ReadLine());
  11. // (P ^ P̃) & P̈
  12. int pReversed = 0;
  13.  
  14. int pTemp = p;
  15. while (pTemp != 0)
  16. {
  17. pReversed <<= 1;
  18. pReversed |= (pTemp & 1);
  19. pTemp >>= 1;
  20. }
  21.  
  22. int answer = (p ^ ~p) & pReversed;
  23. Console.WriteLine(answer);
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment