i want understand function does, logic behind it.
i've searched every term on own (ex: size_t
, bitset
...) still want know how logic flows?
size_t popcount(size_t n) { std::bitset<sizeof(size_t) * char_bit> b(n); return b.count(); }
returns number of bits in bitset b
set (i.e. have value of 1).
size_t popcount(size_t n)
passes n
number of bits set in bitset.
std::bitset<sizeof(size_t) * char_bit> b(n);
creates std::bitset
return b.count();
check documentation std::bitset
see std::bitset::count
returns , answers question. see std::bitset
standard library provided template class storing bits.once understand rest pretty loking in documentation know functionality class provides , mapping how code uses it.
Comments
Post a Comment