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;
- using System.Numerics;
- class InvertingBits
- {
- static void Main(string[] args)
- {
- int n = 9;
- //number n as string
- string nAsStr = Convert.ToString(n, 2);
- //declare empty string
- string maskPrepare = string.Empty;
- //fill string with ones - "1111"
- for (int i = 0; i < nAsStr.Length; i++)
- {
- maskPrepare += 1;
- }
- //convert string to int
- int mask = Convert.ToInt32(maskPrepare, 2);
- int result = n ^ mask;
- Console.WriteLine(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement