Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
特定のビットとビットの範囲にアクセスする必要があることに取り組んでいます。特定のビットに簡単にアクセスできるので、bitset を使用することにしました。ビットの範囲 (サブセット) を抽出するにはどうすればよいですか?
方法A:
return (the_bitset >> start_bit).to_ulong();
方法B(私のマシンでは方法Aより100倍速い):
unsigned long mask = 1; unsigned long result = 0; for (size_t i = start_bit; i < end_bit; ++ i) { if (the_bitset.test(i)) result |= mask; mask <<= 1; } return result;