Uint

class UintType

Bases: pygears.typing.uint.IntegerType

Fixed width generic unsigned integer data type.

Generic parameters:

N: Bit width of the Uint representation

Uint is a generic datatype derived from Integer. It represents unsigned integers with fixed width binary representation. Concrete data type is obtained by indexing:

>>> u16 = Uint[16]
__sub__(other)

Returns a Tuple of the result type and overflow bit.

>>> Uint[16] - Uint[8]
Tuple(Uint[16], Bool)
args

Returns a list of values supplied for each generic parameter.

>>> Tuple[Uint[1], Uint[2]].args
[Uint[1], Uint[2]]
base

Returns base generic class of the type.

>>> assert Uint[16].base == Uint
fields

Returns the names of the generic parameters.

>>> Tuple[Uint[1], Uint[2]].fields
('f0', 'f1')
>>> Tuple[{'u1': Uint[1], 'u2': Uint[2]}].fields
('u0', 'u1')
is_generic()

Return True if no values have been supplied for the generic parameters.

>>> Uint.is_generic()
True
>>> Uint['template'].is_generic()
False
is_specified

Return True if all generic parameters were supplied concrete values.

>>> Uint['template'].is_specified()
False
>>> Uint[16].is_specified()
True
items()

Generator that yields (key, element) pairs.

keys()

Returns a list of keys that can be used for indexing the type.

>>> Int[8].keys()
[0, 1, 2, 3, 4, 5, 6, 7]
templates

Returns a list of templated generic variables within the type. The type is searched recursively. Each template is reported only once.

>>> Tuple[Tuple['T1', 'T2'], 'T1'].templates
['T1', 'T2']
class Uint

Bases: pygears.typing.uint.Integer

Implements the Uint type instance.

Parameters

val – Integer value to convert to Uint

Uint is a generic datatype derived from Integer. It represents unsigned integers with fixed width binary representation.

>>> Uint[16](0xffff)
Uint[16](65535)
__getitem__(index)

Returns the value of the indexth bit in the number representation.

>>> Integer[8](0b10101010)[5]
1
>>> Integer[8](0b10101010)[1::2]
Uint[4](15)
__int__()

Returns builtin integer type

>>> type(int(Integer[8](0)))
<class 'int'>
__len__()

Returns the number of bits used for the representation

>>> len(Integer[8](0))
8
bit_length() → int

Number of bits necessary to represent self in binary. >>> bin(37) ‘0b100101’ >>> (37).bit_length() 6

decode(val)

Creates Integer object from any int-convertible object val.

>>> Integer[8].decode(0xffff)
Integer[8](255)
width

Returns the number of bits used for the representation

>>> Integer[8](0).width
8