rvtypes.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. class uint32:
  2. def __init__(self,number):
  3. number &= 0xFFFFFFFF
  4. if number < 0:
  5. number += 0x100000000
  6. self.value = number
  7. def __add__(self,other):
  8. try:
  9. return uint32(self.value+other.value)
  10. except:
  11. return uint32(self.value+other)
  12. def __sub__(self,other):
  13. try:
  14. return uint32(self.value-other.value)
  15. except:
  16. return uint32(self.value-other)
  17. def __and__(self,other):
  18. try:
  19. return uint32(self.value & other.value)
  20. except:
  21. return uint32(self.value & other)
  22. def __gt__(self,other):
  23. try:
  24. return self.value > other.value
  25. except:
  26. return self.value > other
  27. def __ge__(self,other):
  28. return self > other - 1
  29. def __lt__(self,other):
  30. try:
  31. return self.value < other.value
  32. except:
  33. return self.value < other
  34. def __le__(self,other):
  35. return self < other + 1
  36. def __rshift__(self,other):
  37. try:
  38. return uint32(self.value >> other.value)
  39. except:
  40. return uint32(self.value >> other)
  41. def __int__(self):
  42. return self.value
  43. def __str__(self):
  44. return str(self.value)
  45. def __repr__(self):
  46. return hex(self.value)
  47. class int32:
  48. def __init__(self,number):
  49. number &= 0xFFFFFFFF
  50. if number & 0x80000000:
  51. number -= 0x10000000
  52. self.value = number
  53. def __add__(self,other):
  54. try:
  55. return uint32(self.value+other.value)
  56. except:
  57. return uint32(self.value+other)
  58. def __sub__(self,other):
  59. try:
  60. return uint32(self.value-other.value)
  61. except:
  62. return uint32(self.value-other)
  63. def __and__(self,other):
  64. try:
  65. return uint32(self.value & other.value)
  66. except:
  67. return uint32(self.value & other)
  68. def __gt__(self,other):
  69. try:
  70. return self.value > other.value
  71. except:
  72. return self.value > other
  73. def __ge__(self,other):
  74. return self > other - 1
  75. def __lt__(self,other):
  76. try:
  77. return self.value < other.value
  78. except:
  79. return self.value < other
  80. def __le__(self,other):
  81. return self < other + 1
  82. def __rshift__(self,other):
  83. try:
  84. return uint32(self.value >> other.value)
  85. except:
  86. return uint32(self.value >> other)
  87. def __int__(self):
  88. return self.value
  89. def __str__(self):
  90. return str(self.value)
  91. def __repr__(self):
  92. return hex(self.value)
  93. if __name__ == '__main__':
  94. a = uint32(5)
  95. b = uint32(6)
  96. print(a+b)
  97. print(int(a))
  98. a -= 2
  99. print(a)