riscemu.types.int32 module
- class riscemu.types.int32.Int32(val: Union[int, c_int, c_uint, Int32, bytes, bytearray, bool] = 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.
- property value: int
The value represented by this Integer :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
- property unsigned_value
Return the value interpreted as an unsigned integer :return:
- shift_right_logical(ammount: Union[Int32, int]) 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)
- classmethod sign_extend(data: Union[bytes, bytearray, int], bits: int)
Create an instance of Int32 by sign extending :param:bits bits from :param:data to 32 bits
- Parameters:
data – The source data
bits – The number of bits in the source data
- Returns:
An instance of Int32, holding the sign-extended value
- class riscemu.types.int32.UInt32(val: Union[int, c_int, c_uint, Int32, bytes, bytearray, bool] = 0)
Bases:
Int32
An unsigned version of :class:Int32.
- property unsigned_value: int
Return the value interpreted as an unsigned integer :return: