4 ms·
I should probably fix that. Is there a clever way to unpack a 5bit signed int other than treating it as unsigned and subtracting 16?
by phoboslab 5y ago
I should probably fix that. Is there a clever way to unpack a 5bit signed int other than treating it as unsigned and subtracting 16?
- adgjlsfhk1 5y agoThat seems easiest.
- wizzwizz4 5y agoEspecially since your compiler will make it a super magical optimised version.
- benlivengood 5y agoYou'll have to shift the values around anyway, so: int intermediate = byte_or_word << N; // N chosen to put the five bits in the highest positions in the int. int value = intermediate >> bits_per_int - 5; Instead of masking rely on arithmetic shift right to keep the sign bit.