Question

I want to do a simple bit mask operation. Lets say

uint64_t a = 348659235483;

Assuming this number is converted to binary, I want to extract the values from bit 6 to 12 (0 is MSB on the right end). What is the smallest code for that?

the binary is

10100010010110110110101101/110101/0011011

So I want to save 110101 which is 53

Was it helpful?

Solution

How about

uint64_t a = 348659235483;
uint64_t result = (a & 0x0fe0) >> 6;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top