```
def reverse(self, x):
neg = False
if x < 0:
neg = True
if -9 <= x <= 9:
return x
rev = 0
x = abs(x)
while x != 0:
rev = rev * (10) + (x % 10)
x //= 10
if rev >= 1<<31:
return 0
if neg:
return rev * -1
return rev
```