返回狼盟编程首页
编程搜索 [狼盟旧档]
论坛统计


请输入搜索关键字:
├─◆ 狼盟首页 > 查看贴子 > 详细信息

楼主

[讨论]Major3_Judge


//    2006.5.12//   3 取 2 表决(多数表决制),既对输入的三个字节进行判断//   000 /1 取 0 (0个数多), 110 /1  取 1 (1个数多)#define  BYTE  charBYTE Major3_Judge(BYTE v1, BYTE v2 ,BYTE v3){    BYTE vx=0x00 ;    char i;    unsigned char temp = 0x01;    if(i=0;i<8;i++)  // BYTE 有 8 位    {        if(v1&temp==v2&temp) vx |= v1&temp;        else {            if(v1&temp==v3&temp)  vx |= v1&temp;            else vx |= v3&temp;  // 如果 v1&temp!=v2&temp 和v1&temp!=v3&temp 都不成立,则 v2&temp ==v3&temp        }        temp = temp<<1 ;    }    return  vx;}#undef  BYTE好象有点不对,希望大家指点!!





vfdff [ 1 楼 ]
2006-08-10 01:02:00
#define  BYTE  charBYTE Major3_Judge(BYTE v1, BYTE v2 ,BYTE v3){    BYTE vx=0x00 ;    BYTE bits= v1&~v2&~v3 | ~v1&v2&v3 ;    vx = v1&~bits | v2&bits;    return  vx;}#undef  BYTE想到答案拉 ,和大家分享以下!!