parity.c

来自「c和指针 学习c语言必须阅读的书籍之一 提高对C语言的掌握理解能力」· C语言 代码 · 共 25 行

C
25
字号
/*
** Check the value for even parity.
*/

int
even_parity( int value, int n_bits )
{
	int	parity = 0;

	/*
	** Count the number of 1-bits in the value.
	*/
	while( n_bits > 0 ){
		parity += value & 1;
		value >>= 1;
		n_bits -= 1;
	}

	/*
	** Return TRUE if the low order bit of the count is zero
	** (which means that there were an even number of 1's).
	*/
	return ( parity % 2 ) == 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?