mirror of
https://github.com/myhdl/myhdl.git
synced 2024-12-14 07:44:38 +08:00
Improved doc string of signed() function
This commit is contained in:
parent
6c5094d280
commit
eb009e879e
@ -444,9 +444,10 @@ class intbv(object):
|
||||
The intbv.signed() function will classify the value of the intbv
|
||||
instance either as signed or unsigned. If the value is classified
|
||||
as signed it will be returned unchanged as integer value. If the
|
||||
value is considered unsigned, the value will be returned as
|
||||
integer value, with the sign being considered by the msb. The msb
|
||||
is the msb as specified by _nrbits.
|
||||
value is considered unsigned, the bits as specified by _nrbits
|
||||
will be considered as 2's complement number and returned. This
|
||||
feature will allow to create slices and have the sliced bits be
|
||||
considered a 2's complement number.
|
||||
|
||||
The classification is based on the following possible combinations
|
||||
of the min and max value.
|
||||
@ -470,12 +471,14 @@ class intbv(object):
|
||||
based on the _nrbits value.
|
||||
|
||||
So the test will be if min >= 0 and _nrbits > 0. Then the instance
|
||||
is considered unsigned and the value is change based on the msb.
|
||||
is considered unsigned and the value is returned as 2's complement
|
||||
number.
|
||||
'''
|
||||
|
||||
# value is considered unsigned
|
||||
if self.min >= 0 and self._nrbits > 0:
|
||||
|
||||
# get 2's complement value of bits
|
||||
msb = self._nrbits-1
|
||||
|
||||
sign = ((self._val >> msb) & 0x1) > 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user