Trailing Zeros Counter (CTZ)

Count trailing zero bits in an integer (CTZ operation)

Ad placeholder (leaderboard)

Count Trailing Zeros (CTZ) tells you how many zero bits sit below the lowest set bit of a number. Unlike leading zeros it is independent of register width, and it equals the exponent of the largest power of two dividing the value. This tool computes it for any non-negative integer in decimal, hex, or binary.

How it works

The tool isolates the lowest set bit by shifting the value right while the bottom bit is zero, counting the shifts:

count = 0
while (value & 1) == 0:
    value >>= 1
    count += 1

That count is the position of the lowest set bit (0-indexed from the right) and the exponent k such that 2^k divides the original number but 2^(k+1) does not. Trailing zeros of zero are undefined because no set bit exists to halt the loop, so the tool flags that case rather than looping forever.

Example and notes

The decimal value 48 is 110000 in binary, with four trailing zeros, so CTZ is 4 and 2^4 = 16 is the largest power of two dividing it. CTZ drives the binary GCD (Stein’s) algorithm, lets allocators verify pointer alignment, and finds the next ready task in a bitmask scheduler. On x86 it is the TZCNT instruction; on ARM it is computed by bit-reversing and applying CLZ. This calculator uses BigInt so the input can be arbitrarily large.

Ad placeholder (rectangle)