-
Notifications
You must be signed in to change notification settings - Fork 0
/
libtypes.py
48 lines (33 loc) · 1.21 KB
/
libtypes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Uint32(int):
MAX_VALUE = 2**32 - 1
def __new__(cls, value):
# 确保值在0到MAX_VALUE之间
return super(Uint32, cls).__new__(cls, value & cls.MAX_VALUE)
def __add__(self, other):
return Uint32(int(self) + int(other))
def __sub__(self, other):
return Uint32(int(self) - int(other))
def __mul__(self, other):
return Uint32(int(self) * int(other))
def __floordiv__(self, other):
return Uint32(int(self) // int(other))
def __mod__(self, other):
return Uint32(int(self) % int(other))
def __pow__(self, other, modulo=None):
return Uint32(int(self) ** int(other))
def __lshift__(self, other):
return Uint32(int(self) << int(other))
def __rshift__(self, other):
return Uint32(int(self) >> int(other))
def __and__(self, other):
return Uint32(int(self) & int(other))
def __or__(self, other):
return Uint32(int(self) | int(other))
def __xor__(self, other):
return Uint32(int(self) ^ int(other))
def __neg__(self):
return Uint32(-int(self))
def __invert__(self):
return Uint32(~int(self))
def __repr__(self):
return f"Uint32({int(self)})"