```
sign = cmp(x, 0)
p = abs(x)
result = 0
while p > 0:
rem = p%10
result = result*10 + rem
p /= 10
# more succinct but less efficient:
#return sign*result * (result < 2**31)
if result > 2**31: return 0
result = sign*result
return result
```