Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- int number = 5;
- string numberBinary = Convert.ToString(number, 2);
- var charArray = numberBinary.ToArray();
- for (int i = 0; i < numberBinary.Length; i++)
- {
- if (charArray[i] == '1')
- {
- charArray[i] = '0';
- }
- else
- {
- charArray[i] = '1';
- }
- }
- string complement = "";
- for (int i = 0; i < numberBinary.Length; i++)
- {
- complement += charArray[i];
- }
- int number11 = Convert.ToInt32(complement, 2);
- Console.WriteLine(number11);
- Console.ReadLine();
- }
Advertisement
Add Comment
Please, Sign In to add comment