Int

class Int

Bases: pygears.typing.uint.Integer

Fixed width generic signed integer data type.

Generic parameters:

N: Bit width of the Int representation

Parameters

val – Integer value to convert to Int

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

>>> i16 = Int[16]
__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