| [val=None][, min=None][, max=None]) |
int(bitstring,
2). The optional min and max arguments can be used to
specify the minimum and maximum value of the intbv object. As
in standard Python practice for ranges, the minimum value is inclusive
and the maximum value is exclusive.
The minimum and maximum values of an intbv object are available as attributes:
Unlike int objects, intbv objects are mutable; this is also the reason for their existence. Mutability is needed to support assignment to indexes and slices, as is common in hardware design. For the same reason, intbv is not a subclass from int, even though int provides most of the desired functionality. (It is not possible to derive a mutable subtype from an immutable base type.)
An intbv object supports the same comparison, numeric, bitwise, logical, and conversion operations as int objects. See http://www.python.org/doc/current/lib/typesnumeric.html for more information on such operations. In all binary operations, intbv objects can work together with int objects. For mixed-type numeric operations, the result type is an int or a long. For mixed-type bitwise operations, the result type is an intbv.
In addition, intbv objects support indexing and slicing operations:
| Operation | Result | Notes |
|---|---|---|
bv[i] |
item i of bv | (1) |
bv[i] = x |
item i of bv is replaced by x | (1) |
bv[i:j] |
slice of bv from i downto j | (2)(3) |
bv[i:j] = t |
slice of bv from i downto j is replaced by t | (2)(4) |
2**i.
bv[i:] returns i bits;
bv[i:j] has i-j
bits. When the low index j is omitted, it defaults
to 0. When the high index i is omitted, it
means ``all'' higher order bits.
0 and 2**w, respectively.
In addition, an intbv object supports the iterator protocol. This makes it possible to iterate over all its bits, from the high index to index 0. This is only possible for intbv objects with a defined bit width.
About this document