我如何從二進制字符串計算并添加到字符串奇偶校驗:26 位韋根格式:位 1 = 位 2 - 13 的偶校驗位 26 奇偶校驗位 14 到 25例如:二進制字符串:1111 1011 0111 0111 1111 1010奇偶計算后:X 1111 1011 0111 0111 1111 1010 Y
1 回答

墨色風雨
TA貢獻1853條經驗 獲得超6個贊
假設您有一個二進制字符串:
var bitString = "10101";
您可以通過一些 LINQ 獲得奇偶校驗:
int bitCount = bitString.Where( c => c == '1' ).Count(); //Count the bits that are set
bool parityOdd = (bitCount & 1) == 1; //See if the count of set bits itself has its low bit set
- 1 回答
- 0 關注
- 240 瀏覽
添加回答
舉報
0/150
提交
取消