Not sure if we would want different names, but would it be fine to add Num.countLeadingZeros and Num.countTrailingZeros. They return the number of consecutive zero bits at the start or end of a number.
So for 0b0011_0000, countLeadingZeros would be 2 and countTrailingZeros would be 4.
both seem fine, although I'd try to get "bits" into the name
e.g. Num.countLeadingZeroBits or Num.leadingZeroBits
because otherwise a beginner might think that (for example) countTrailingZeroes 1_000_000 would return 6 :sweat_smile:
Fun fact, countTrailingZeroes 1_000_000 does return 6 :)
I wrote it down and then thought "what are the odds that by sheer coincidence....naaaaah I'm not gonna check"
so of COURSE it turned out to be the same :laughing:
Anything that's 10^n will have n trailing zeros when written in binary
(10 = 2*5, so you get exactly one factor of 2 per factor of 10)
ha, makes sense
ok well I'm sure there are numbers where it's different, e.g. (I'm also not bothering to check this :laughing:) 1_700_000 or maybe 1_070_000
Any number where when you lop off the zeros in base 10 still results in an even number, will differ in the number of zeros base 2 and base 10.
So actually neither of those examples work ;)
ok so...1_400_000
Bingo!
Anyway, this all reinforces the point that this could be super confusing
yeah I didn't even think of that - a lot of the time it would give the same answer by coincidence, so depending on which numbers you chose in test cases/local development, you might not even realize it until getting something in production :dizzy:
Last updated: Jun 16 2026 at 16:19 UTC