Guest User

Untitled

a guest
Feb 11th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1.             uint given = 75;
  2.             Console.WriteLine(Convert.ToString(given, 2));
  3.             int len = Convert.ToString(given, 2).Length;
  4.  
  5.             for (int i = 0; i < len; i++)
  6.             {
  7.                 uint mask = (uint)1 << i;
  8.                 if ((given & mask) == 0)  //the i-th bit is unset
  9.                 {
  10.                     given = given | mask; //set
  11.                 }
  12.                 else  //the i-th bit is set
  13.                 {
  14.                     given = given & (~mask);
  15.                 }
  16.             }
  17.             Console.WriteLine(Convert .ToString (given ,2));
Add Comment
Please, Sign In to add comment