Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BitwiseOperations
- {
- class Program
- {
- static bool Contains(int mask, int el)
- {
- return (mask & (1 << el)) != 0;
- }
- static void Insert(ref int mask, int el)
- {
- mask |= (1 << el);
- }
- static void Remove(ref int mask, int el)
- {
- mask &= ~(1 << el);
- }
- static void Change(ref int mask, int el)
- {
- mask ^= (1 << el);
- }
- static void Main(string[] args)
- {
- int a = 0;
- Insert(ref a, 0);
- Insert(ref a, 3);
- Insert(ref a, 5);
- Console.WriteLine(Convert.ToString(a, 2).PadLeft(32, '0'));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement