Учитывая серию байтов, какой самый быстрый способ узнать номер 1 бита? < /p>
Код: Выделить всё
#include
constexpr size_t nbytes = 256;
std::array bytes;
size_t table[256]{0, 1, 1, 2, 1, ...}; // define table from 0x00 to 0xff
size_t count1() {
size_t res = 0;
for (size_t i{0}; i < nbytes; ++i) { res += table[static_cast(bytes[i])];}
return res;
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... y-of-bytes