我有分配使用移位添加两个无符号字符。s 是总结,p 是“溢出”我不知道怎么说。这是我的代码,有问题,它总是打印 0 0
unsigned char get_bit(unsigned char x, int i){
return (x>>i)&1;
}
void set_bit(unsigned char *x, int i, unsigned char b){
*x=(b<<i)|(*x&~(1<<i));
}
void f(unsigned char x, unsigned char y, unsigned char *s, unsigned char *p){
int i;
unsigned char k=0,c=0;
for(i=0;i<8;i++){
unsigned char m=0;
m=get_bit(x,i)+get_bit(y,i)+c;
if(m==2) {
m=0;
c=1;
}
else c=0;
set_bit(s,i,m);
}
*s=(unsigned char)k;
*p=(unsigned char)c;
}