Get the latest tech news
Zero or Sign Extend
A while back I had to deal with a bit-packed format that contained a list of integer values encoded in one of a pre-defined sets of bit widths, where both the allowed bit widths and the signed-ness…
In C/C++, this explicitly relies on shifting something into the sign bit, which depending on the exact flavor of language standard you’re using is either not allowed or at best fairly recently(voted into C++20) legal. A minor variant is to skip the first mask entirely and think purely in terms of the correction we need to do. Going back to my original problem, I had a mixture of different bit widths and needed to support either signed or unsigned.
Or read this on Hacker News