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.
16ビットワードの配列があり、ビット番号を指定したときに適切なワードに設定するビットを計算したいと思います。たとえば、ビット24は2番目のワードの8番目のビットを設定します。
除算を使用して配列内のインデックスを取得するだけで、余りは設定するビット番号になります。
int N = 24; int index = N / 16; int bit = N % 16; words[index] |= (1 << bit);