Leading Zeros Counter (CLZ)

Count leading zero bits in an integer (CLZ operation)

Ad placeholder (leaderboard)

Count Leading Zeros (CLZ) tells you how many zero bits sit above the highest set bit of a number in a fixed-width register. It is a single CPU instruction on modern hardware and a building block for fast logarithms, normalisation, and power-of-two rounding. This tool computes it for any value and width from 8 to 128 bits.

How it works

For a value that fits within the chosen width w, the leading-zero count is the width minus the number of significant bits:

significant bits = number of bits to write the value in binary
CLZ              = w − significant bits      (and CLZ = w when value is 0)

The position of the highest set bit is then w − CLZ − 1, counting from the least-significant bit as position 0. Because leading zeros depend entirely on the register size, the tool zero-pads the binary form to the selected width so you can see the leading zeros directly.

Example and notes

The hex value 0x00010000 is 2^16. In a 32-bit register it is written as fifteen zeros, a single 1, then sixteen zeros, giving a CLZ of 15 and a highest set bit at position 16. The integer base-2 logarithm follows immediately: floor(log2(x)) = w − CLZ − 1. CLZ also lets you round up to the next power of two and normalise floating-point numbers. Be aware that on some processors CLZ of zero is undefined; this tool defines it as the full width for convenience.

Ad placeholder (rectangle)