[Solved] How to add parity bits on c# [closed]


This should do it:

Console.WriteLine("Please enter a 7- bit binary number");

string number = Console.ReadLine();

int count = 0;

for(int i = 0; i < number.Length; i++)
{
   if(number[i] == '1')
   {
      count++;
   }
}

Console.WriteLine("Your number with parity bit is "+ number + (count % 2).ToString());

I’d imagine this is beyond your current level, but this should also work:

Console.WriteLine("Please enter a 7- bit binary number");

string number = Console.ReadLine();

string parityBit = (number.Where(c => c == '1').Count() % 2).ToString();

Console.WriteLine("Your number with parity bit is "+ number + parityBit);

2

solved How to add parity bits on c# [closed]