I am trying to flip the bits of an unsigned 32-bit integer and output the resultant integer. The following is my code.
int numberOfTries = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < numberOfTries; i++)
{
uint input = Convert.ToUInt32(Console.ReadLine());
byte[] bInput = BitConverter.GetBytes(input);
if (BitConverter.IsLittleEndian)
Array.Reverse(bInput);
byte[] result = bInput;
BitArray b = new BitArray(new byte[] { result });
b.Not();
uint res = 0;
for (int i2 = 0; i2 != 32; i2++)
{
if (b[i2])
{
res |= (uint)(1 << i2);
}
}
Console.WriteLine(res);
}
However, the compiler complains that "Cannot implicitly convert type 'byte[]' to 'byte' " on the line where I declare BitArray b. I have declared it as a byte[] and have no idea why this error is being thrown.