bool Unsigned::Greater(Unsigned& b) { bool ret_val = true; assert(this->Width() == b.Width()); for(int idx = this->Width()-1; idx >= 0; idx--) { if((!this->Get_Bit(idx) && b.Get_Bit(idx))) { ret_val = false; break; } else if(this->Get_Bit(idx) && !b.Get_Bit(idx)) break; } return(ret_val); }
void Unsigned::Concatenate(Unsigned& b) { Unsigned tmp(_width + b._width); for(int idx = 0; idx < b.Width(); idx++) { tmp.Set_Bit(idx, (b.Get_Bit(idx) ? true : false)); } for(int idx = 0; idx < this->_width; idx++) { tmp.Set_Bit(idx + b.Width(), (this->Get_Bit(idx) ? true : false)); } this->Swap(tmp); }
void Unsigned::Add(Unsigned& b) { bool carry = false; assert(this->_width == b.Width()); for(int idx = 0; idx < b.Width(); idx++) { bool abit = this->Get_Bit(idx); bool bbit = b.Get_Bit(idx); bool sum = (abit ^ bbit ^ carry); this->Set_Bit(idx,sum); carry = (abit & bbit) | ((abit | bbit) & carry); } this->Sign_Extend(); }