riscemu.types.int32 module

class riscemu.types.int32.Int32(val: Union[int, ctypes.c_int, ctypes.c_uint, riscemu.types.int32.Int32, bytes, bytearray] = 0)

Bases: object

This class implements 32bit signed integers (see UInt32 for unsigned integers)

It implements basically all mathematical dunder magic methods (__add__, __sub__, etc.)

You can use it just like you would any other integer, just be careful when passing it to functions which actually expect an integer and not a Int32.

__init__(val: Union[int, ctypes.c_int, ctypes.c_uint, riscemu.types.int32.Int32, bytes, bytearray] = 0)
property value: int

The value represented by this Integer :return:

unsigned() riscemu.types.int32.UInt32

Convert to an unsigned representation. See :class:Uint32 :return:

to_bytes(bytes: int = 4) bytearray

Convert to a bytearray of length :param:bytes

Parameters

bytes – The length of the bytearray

Returns

A little-endian representation of the contained integer

signed() riscemu.types.int32.Int32

Convert to a signed representation. See :class:Int32 :return:

property unsigned_value

Return the value interpreted as an unsigned integer :return:

shift_right_logical(ammount: Union[riscemu.types.int32.Int32, int]) riscemu.types.int32.Int32

This function implements logical right shifts, meaning that the sign bit is shifted as well.

This is equivalent to (self.value % 0x100000000) >> ammount

Parameters

ammount – Number of positions to shift

Returns

A new Int32 object representing the shifted value (keeps the signed-ness of the source)

class riscemu.types.int32.UInt32(val: Union[int, ctypes.c_int, ctypes.c_uint, riscemu.types.int32.Int32, bytes, bytearray] = 0)

Bases: riscemu.types.int32.Int32

An unsigned version of :class:Int32.

unsigned() riscemu.types.int32.UInt32

Return a new instance representing the same bytes, but signed :return:

property unsigned_value: int

Return the value interpreted as an unsigned integer :return:

shift_right_logical(ammount: Union[riscemu.types.int32.Int32, int]) riscemu.types.int32.UInt32

see Int32.shift_right_logical

Parameters

ammount – Number of positions to shift

Returns

A new Int32 object representing the shifted value (keeps the signed-ness of the source)