D
Digital Puer
Hi, suppose I have an unsigned long long. I would like to extract
the front 'n' bits of this value and convert them into an integer.
For example, if I extract the first 3 bits, I would get an int between
0 and 7 (=2^3-1). Could someone please help out?
I can assume the largest returned value fits in an int. Also,
I'm on a big-endian PPC (AIX), in case that matters.
Ideally, I'd like to implement a prototype like:
int extractFrontBits(unsigned long long value, int num_bits);
the front 'n' bits of this value and convert them into an integer.
For example, if I extract the first 3 bits, I would get an int between
0 and 7 (=2^3-1). Could someone please help out?
I can assume the largest returned value fits in an int. Also,
I'm on a big-endian PPC (AIX), in case that matters.
Ideally, I'd like to implement a prototype like:
int extractFrontBits(unsigned long long value, int num_bits);