-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryIdentificationChangeColor
More file actions
42 lines (42 loc) · 1.76 KB
/
BinaryIdentificationChangeColor
File metadata and controls
42 lines (42 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
class BinaryIdentificationChange
{
static void Main()
{
while (true)
{
Console.Write("Enter number to turn into bits:");
short number = short.Parse(Console.ReadLine());
Console.WriteLine("Bit representation is:{0}",Convert.ToString(number, 2).PadLeft(16, '0'));
{
Console.Write("Enter bit to be identified:");
int bitIdent = int.Parse(Console.ReadLine());
int shifted = number >> bitIdent;
int maskIdent = 1;
Console.WriteLine("Mask = 1");
int result = shifted & maskIdent;
Console.WriteLine("The bit is:{0}", result);
if (result == 1)
{
Console.WriteLine("Change identified bit {0} to 0", bitIdent);
int mask = 1 << bitIdent;
Console.WriteLine("Mask bit is:{0}", Convert.ToString(mask, 2).PadLeft(16, '0'));
int newNumber = number ^ mask;
string newNumberBit = Convert.ToString(newNumber, 2).PadLeft(16, '0');
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Original bit is:{0,17}", Convert.ToString(number, 2).PadLeft(16, '0'));
Console.WriteLine("Changed bit is:{0,18}", newNumberBit);
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("THE VALUE OF THE BIT IS ZERO (0)");
Console.WriteLine();
Console.WriteLine();
Console.ResetColor();
}
}
}
}
}