Tested:
```python
In [8]: int('0xff',16)
Out[8]: 255

In [9]: int('0x80000000',16)
Out[9]: 2147483648

In [10]: h = '0x80000000'

In [11]: int(h,16) if int(h,16) < int('0x80000000', 16) else (-int('0xffffffff', 16)+int(h,16)-1)
Out[11]: -2147483648

In [12]: h = '0x7FFFFFFF'
In [13]: int(h,16) if int(h,16) < int('0x80000000', 16) else (-int('0xffffffff', 16)+int(h,16)-1)
Out[13]: 2147483647

In [14]: h='0xFFFFFFFF'

In [15]: int(h,16) if int(h,16) < int('0x80000000', 16) else (-int('0xffffffff', 16)+int(h,16)-1)
```
But the algorithm can get cleaned up and more efficient with:

```python
def sint(hstr):
    '''
    Converts a hex string to a 32-bit signed integer (twos compliment).
    '''
    x = int(hstr,16)
    return x if (x < 2147483648) else ((-4294967295 + x )-1)
```