Venciity

BitWiseOperators - clear the bit at position p

Jan 30th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ex2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // set the bit at postion p to 0 ( clear the bit at position p )
  14.             int p = 5;
  15.             int n = 42;                 //00101010
  16.             int mask = ~(1 << p);       //00000101
  17.             int result = n & mask;      //00000001
  18.             Console.WriteLine(result);  //10
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment