This is assuming a two's compliment number system right? So it may not be entirely portable, although should work on anything built since I started writing code.