count_leading_zeros(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– count_leading_zeros(9) β€” NAME πŸ’–

Hey bestie, welcome to the count_leading_zeros(9) page in the Kernel API Manual ✨ This one is literally about counting zeros, and it's giving main character energy:

count_leading_zeros β€” Count the number of zeros from the MSB back πŸŽ€


✨ SYNOPSIS ✨

int count_leading_zeros (unsigned long x );

πŸŽ€ ARGUMENTS πŸŽ€

  • x β€” The value. That's it, that's the whole input, no cap πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so the vibe is: count the number of leading zeros from the MSB going towards the LSB in x. Periodt πŸ’–

The results go like this:

  • If the MSB of x is set, the result is 0. Slay, no zeros to count πŸ”₯
  • If only the LSB of x is set, then the result is BITS_PER_LONG-1. Iconic edge case behavior πŸŽ€
  • If x is 0, then the result is BITS_PER_LONG. That's the full count, bestie 😭

πŸ‘‘ SEE ALSO πŸ‘‘

  • Kernel file ./include/linux/count_zeros.h β€” go check it out, iykyk πŸ¦‹
  • count_trailing_zeros(9) β€” the other zero-counting bestie, matching energy πŸ’…

mwah πŸ’– this page lives in the Kernel API Manual, source ./include/linux, dated October 2026 β€” bye bestie, go count those zeros ✨

πŸ“¦ where this page comes from