Sum = One + Two + Sum;//二进制求和(注意上次低位向高位的进位) Tmp = (One & 0xf0) + (Two & 0xf0);//为半进位做准备
if ((Tmp != (Sum & 0xf0)) //判断半进位,即D3向D4的进位,例如8+9=17->0x11,不判将为0x01 || ((Sum & 0x0f) > 9))//上句若无半进位,还要考虑BCD<=9的问题 { Sum += 6;//BCD码低4位调整,哈哈~~~这句在教课书里都有的~~~ } if (Sum >= 0xa0) {//BCD码高4位调整 Sum += 0x60;//注意"混球"~~~ }
|