Re: [myhdl-list] Slicing an unsigned intbv to a signed one
Brought to you by:
jandecaluwe
From: Günter D. <dan...@we...> - 2008-06-13 18:19:38
|
Christopher L. Felton wrote: > Ok, below was my quick test to double check if it could be done. A > real implementation probably need more thought (if feasible at all). ... I think what you need to do is not just multiply by -1, but create a mask that is ORed with the actual number. If the sign bit gets set, the mask will be all 1 upwards from the sign bit and all 0 down to bit 0. Then OR that with the current intbv value. So instead of this: self._val = -1 * self._val do this: self._val = (-1 << self._nrbits-2) | self._val This is basically a merging between the existing bits below the sign bit and the sign change to negative. For clearing the sign bit the simplest way would be to slice the bits below the sign bit out and return them as a new intbv value. Guenter |