Пример #1
0
void Unsigned::Subtract(Unsigned& b)
{
  assert(_width == b.Width());
  Unsigned one_val(b.Width(),"_b1");

  Unsigned tmp(b.Width());
  tmp = b;
  tmp.Complement();
  tmp.Add(one_val);
  
  this->Add(tmp);
}
Пример #2
0
void Unsigned::Multiply(Unsigned& b )
{
  assert(this->_width == b.Width());

  if(b.Width() > 64)
    {
      cerr << "Error: multiply supported for integers which are up to 64 bits wide" << endl;
      cerr << "          will return junk " << endl;
      return;
    }

  this->_bit_field[0] = this->_bit_field[0] * b._bit_field[0];
}
Пример #3
0
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);
}
Пример #4
0
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();
}
Пример #5
0
void Unsigned::Divide(Unsigned& b)
{
  assert(_width == b.Width());
  if(_width > 64)
    {
      cerr << "Error: divide supported for integers which are up to 64 bits wide" << endl;
      cerr << "          will return junk " << endl;
      return;
    }
  
  this->_bit_field[0] = this->_bit_field[0] / b._bit_field[0];
}
Пример #6
0
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);
}
Пример #7
0
void Unsigned::Xor(Unsigned& b)
{
  assert(this->Width() == b.Width());
  for(int idx = 0; idx < this->Array_Size(); idx++)
    this->_bit_field[idx] = (this->_bit_field[idx] ^ b._bit_field[idx]);
}