Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. using System;
  2.  
  3. class ModifyBit
  4. {
  5. static void Main()
  6. {
  7.  
  8. ulong N = ulong.Parse(Console.ReadLine());
  9. byte P = byte.Parse(Console.ReadLine());
  10. byte v = byte.Parse(Console.ReadLine());
  11. if (P >= 0 && P < 64)
  12. {
  13. if (v == 0)
  14. {
  15.  
  16. ulong mask = (ulong) ~(1 << P);
  17. ulong result = N & mask;
  18. Console.WriteLine(result);
  19. }
  20. else if (v == 1)
  21. {
  22. ulong mask = (ulong)1 << P;
  23. ulong result = N | mask;
  24. Console.WriteLine(result);
  25. }
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement