```
int ans[32] = {0};// max is 32
int e = 0;
int sign = x >= 0 ? 1 : -1;
x *= sign;
while (x /10 != 0) {
int v = x % 10;
ans[e++] = v;
x /= 10;
}
ans[e] = x;
int a = 0;
for (int i = 0; i <= e; i++) {
a += ans[i] * pow(10, e-i);
if (a >> 31 == -1) {//a is signed integer,
return 0;
}
}
return a * sign;
```