The FixedPointBits Class

Examples are just a click away

Boxes like this link to example code.

class fixedpoint.FixedPointBits

FixedPointBits inherits from int and adds item access. You should not need to instantiate this, but this allows for the FixedPoint.bits attribute to be indexed, sliced, and mapped.




True for signed, False for unsigned.




Number of integer bits.




Number of fractional bits.



This is the built-in square bracket [] operator.


key (int or slice or str) – Bit index, slice, or mapping

Return type

int or str

  • 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.


When key is an int, a single bit is accessed in FixedPoint.bits. Index 0 is the LSb and index \(m + n - 1\) is the MSb.

Jump to Examples


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 as FixedPointBits 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 digit str (indexed from 0 to \(m + n - 1\)).

Jump to Examples


Common bit slices are mapped to string keywords:

Key String

Bit Slice



integer bits only

FixedPointBits.m > 0



fractional bits only

FixedPointBits.n > 0



most significant bit




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