The FixedPointBits Class¶
Examples are just a click away
Boxes like this link to example code.
-
class
fixedpoint.
FixedPointBits
¶ FixedPointBits
inherits fromint
and adds item access. You should not need to instantiate this, but this allows for theFixedPoint.bits
attribute to be indexed, sliced, and mapped.-
__getitem__
(key)¶ Note
This is the built-in square bracket
[]
operator.- Parameters
- Return type
- Raises
KeyError – Unsupported mapping string
IndexError – Invalid slice step or index out of range
The square brackets allow access to one or more bits at a time. No matter the access scheme (indexing, slicing, or mapping, described below), the return value is always shifted to be no more than N bits, where N is the number of bits accessed. E.g., accessing 3 bits will return an integer in the range [0, 23), regardless of where the are located in the
FixedPointBits
.Indexing
When key is an
int
, a single bit is accessed inFixedPoint.bits
. Index 0 is the LSb and index \(m + n - 1\) is the MSb.Jump to Examples
Slicing
When key is a
slice
(either an explicit slice object, or generated by using one or more:
s), one or more bits can be accessed. With bits asFixedPointBits
and integers A, B, and C such that A > B:bits[A:B:C]
returns bits A down to B (inclusive) with index 0 being the LSb and \(m + n - 1\) being the MSb. C can be omitted, but must be -1 if specified.bits[B:A:C]
returns bits A up to B (inclusive) with index 0 being the MSb and \(m + n - 1\) being the LSb. C can be omitted, but must be 1 if specified.bits[A:A:C]
with C == -1 returns bit A within index 0 being the LSb and \(m + n - 1\) being the MSb.bits[B:B:C]
with C == 1 returns bit B within index 0 being the MSb and \(m + n - 1\) being the LSb.
Any slicing format not specified above treats the
FixedPointBits
as a binary digitstr
(indexed from 0 to \(m + n - 1\)).Jump to Examples
Mapping
Common bit slices are mapped to string keywords:
Key String
Bit Slice
Assumptions
'm'
integer bits only
FixedPointBits.m
> 0'int'
'n'
fractional bits only
FixedPointBits.n
> 0'frac'
's'
most significant bit
is True'sign'
'msb'
–
'lsb'
least significant bit
If the mapping is accessed and the assumption(s) for that mapping are not satisfied, a
KeyError
is raised.When the key string is UPPERCASED, the return value is a
str
of binary bits.Jump to Examples
-