This Christmas day, I am plagued by this negative nibble mystery. I have some bytes in a byte array that I want to split into nibbles
x = bytes(n)
x = x << 28'cause the left 4 bits to overflow so we remain with only the right 4 bits
x = x >> 28
This code works fine, except for some integers including those between 100 and 110. I have, however, solved this problem by ANDing 15 to whatever value the function returns.
I have tried thinking about how the negative nibbles come about, but I haven't managed to find out how. This is where you come in. May someone please explain how it happens?