驱动芯片L9945的odd parity的计算方法

 

odd parity 的计算方法,仅供参考。

该实现局限于MCU的大小端,如果大小端不同会导致不同,需要修改源代码。

uint8 l9945_oddParityCalcu(uint32 datain)
{
	uint32 dataIn_uint32;
	uint32 result_uint32 = 0;
	uint32 debug_uint32;

	uint16 i;

	dataIn_uint32 = datain;

	for(i = 1; i < 32; i++)
	{
		debug_uint32 = ((dataIn_uint32>>i)&0x00000001);
		result_uint32 += debug_uint32;
	}

	/*
	 * PARITY - Parity bit, based on even parity calculation
		0: If the number of 1 is odd
		1: If the number of 1 is even
	 * */
	if(result_uint32%2 == 1)
	{
		return 0; //the number of 1 is odd
	}
	else
	{
		return 1;
	}
}

  

 

posted @ 2020-10-14 17:06  panrui  阅读(627)  评论(1编辑  收藏  举报