c++程序设计实验报告 下载本文

}

return res; }

binary operator -( binary n2) {

unsigned borrow=0; int value;

binary res=\

for(int i=15; i>=0; i--) {

value=(bits[i]=='0'?0:1)-(n2.bits[i]=='0'?0:1)+borrow; res.bits[i]=(value==-1||value==1?'1':'0');

borrow=(value==-1||borrow!=0&&(value==0||value==1)?1:0); }

return res; } 2.

friend binary operator~(binary n2) {

int a=~int(n2); binary res(a); return res; }

friend binary operator&(binary n1,binary n2) {

int a=int(n2)&int(n1); binary res(a); return res; }

friend binary operator|(binary n1,binary n2) {

int a=int(n2)|int(n1); binary res(a); return res; }