Thursday, 15 September 2011

How to add parity bits on c# -



How to add parity bits on c# -

please help want c# come 1 time comes up

please come in 7-bit binary number:

0010011

your number parity bit is:

00100111

this code have come with, wrong please can right alright?

{ console.writeline("please come in 7- bit binary number"); string number = console.readline(); int count1 = 0; int count2 = 0; for(int = 0; < number.length; i++) { count1++; } else { count2++; } if (count1 < count2) console.writeline("your number parity bit "+ number+ "1"); } else { console.writeline("your number parity bit "+ number + "0"); } } }

}

thx in advance help

this should it:

console.writeline("please come in 7- bit binary number"); string number = console.readline(); int count = 0; for(int = 0; < number.length; i++) { if(number[i] == '1') { count++; } } console.writeline("your number parity bit "+ number + (count % 2).tostring());

i'd imagine beyond current level, should work:

console.writeline("please come in 7- bit binary number"); string number = console.readline(); string paritybit = (number.where(c => c == '1').count() % 2).tostring(); console.writeline("your number parity bit "+ number + paritybit);

c# parity

No comments:

Post a Comment