Read binary and choose a width
Separate numeric value, written representation, and the width of the type.
Understand the idea
Bit k contributes 2^k to an unsigned integer. Decimal 13 and binary 1101 describe the same value: 8 + 4 + 1. Leading zero bits change the written width, not the value. A mask uses these positions to represent presence or a choice.
Trace a small example
13 has three set bits, highest set-bit index 3, and bit width 4. These are different quantities. Use an unsigned type for masks and a typed one such as 1ULL before shifting; an ordinary 1 is an int even if its result is assigned to a wider variable.
Conditions and cost
A shift count must be at least zero and less than the width of the promoted left operand. Never shift by the type width. Zero needs separate handling for formulas that assume a highest set bit.
What is the value of binary 10110?
Turn the idea into code
Write 37 in binary and name its set-bit indices.
Give me a hint
Subtract powers of two from largest to smallest.
Show the explained solution
37 = 32 + 4 + 1 = binary 100101. The set-bit indices are 5, 2, and 0.
Your notes
Mark complete when you can explain it yourself.