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

 

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 @   panrui  阅读(666)  评论(1编辑  收藏  举报
点击右上角即可分享
微信分享提示