I would like to save some space by truncating my pointer addresses by 1 byte. My pointers are guaranteed to be 16-byte memory aligned. Thus, I can guarantee that those 4 bottom bits can be truncated.
typedef struct node_t {
uintptr_t prev : 29;
uintptr_t next : 29;
} node;
I am struggling to restore those bottom-most bytes. Bit shifting 4 bits to the left in an attempt to restore the zeroes in the bottom-most bits only erases the data from the front-most bytes.
node->next = ((uintptr_t) ptr_addrs >> 4); // successfully stores truncated pointer ex: 0x1024ff010
printf("%p\n", node->next); // prints '0x1024ff01'
How do I convert the bitfield back to its original value (basically appending a zero to this bitfield)?