check out <a href="https://zjkmxy.github.io/posts/2021/11/twos-complement-2-adic/" rel="nofollow">https://zjkmxy.github.io/posts/2021/11/twos-complement-2-adi...</a> for a discussion of some relevant mathematics; cool stuff<p>there is also a lot of good stuff concerning such computational tricks and their relation with 2-adics in section 7.1.3 (Bitwise Tricks and Techniques) of volume 4A of The Art of Computer Programming: <a href="https://www-cs-faculty.stanford.edu/~knuth/fasc1a.ps.gz" rel="nofollow">https://www-cs-faculty.stanford.edu/~knuth/fasc1a.ps.gz</a>