-6

unsigned long long a如何将其位分成 3 个整数,每个整数都有 [1-2, 3-5, 6-7] 位?

4

1 回答 1

5
unsigned long long a;
// bits 1 and 2 assuming 0 indexed
int first = static_cast<int>((a & (3ULL<<1))>>1);
// bits 3 and 5 assuming 0 indexed
int second = static_cast<int>((a & (3ULL << 3)) >> 3);
// bits 6 and 7 assuming 0 indexed
int third = static_cast<int>((a & (3ULL << 5)) >> 5);
于 2013-03-20T10:33:21.727 回答