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);