|
楼主 |
发表于 2005-12-9 12:59:23
|
显示全部楼层
- unsigned char a,b;
- a = 0x12, b = 0x89;
- //cy:进位标志
- //ov:溢出标志
- //ac:辅助进位标志
- //p:奇偶校验标志
- unsigned char cy,ac,ov,p;
- cy = unsigned char( unsigned short(a) + b / 256 );
- ac = ( ((a & 0x0f) + (b & 0x0f)) & 0x10 ) >> 4;
- signed int tmp = (signed int(a) + signed int(b));
- if( (tmp > 128) || (tmp < -127) )
- ov = 1;
- else
- ov = 0;
- a += b;
复制代码
这是我写的,感觉这样效率很低,有没有高效一点的,还有奇偶校验不知道该怎么写。 |
|