Answer the question
In order to leave comments, you need to log in
How to pack numbers without bit operations?
There are 4 bytes of space. There are several polbyte numbers. How to pack half-byte numbers into a 4-byte number using arithmetic operations?
Answer the question
In order to leave comments, you need to log in
How to pack half-byte numbers into a 4-byte number using arithmetic operations?
uint32_t put_nibble(uint32_t v, int nibble_index, uint32_t nibble)
{
uint32_t p = 1;
uint32_t r;
int i;
for (i = 0; i < nibble_index; ++i)
p *= 16;
r = (v % p) + (nibble * p);
if (nibble_index < 7)
r += (v / (p * 16)) * p * 16;
return r;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question