Count Trailing Zeros Calculator for Binary Numbers – Free

This count trailing zeros calculator reports how many 0 bits follow the last 1 at the least significant end of a binary word. For a nonzero word that is also the index of the lowest set bit.

How to use the Trailing zeros Calculator tool

  1. Enter a binary word in the Binary digits box, such as 00101000.
  2. Select Convert. The Example button runs the sample 01001101, which is odd and so has no trailing zeros.
  3. Read the count of trailing zero bits in the Result box.
  4. Select Copy to copy the number, or Clear to try a different word.

What trailing zeros tell you

Trailing zeros are the consecutive 0 bits at the right end of a binary number. Each one is a factor of two, so the count, often written ctz(x), is the largest k for which 2^k divides x. An odd number has a count of 0. The number 40 is 101000 in binary, has three trailing zeros and equals 8 times 5.

For any nonzero word the count is identical to the position of the lowest set bit, numbered from the right starting at zero. Unlike a leading zero count, it does not depend on how wide the word is.

Worked example and the zero case

The calculator scans from the right end of the digits you enter and stops at the first 1. Leading zeros and spaces make no difference. The last line of the example below is the special case: a word with no 1 bit has nothing to stop the scan, so every digit is counted and the result equals the word length.

Hardware and libraries mostly agree with this convention. The x86 TZCNT instruction, std::countr_zero in C++20 and trailing_zeros in Rust return the operand width for zero. The older BSF instruction and __builtin_ctz leave the zero case undefined.

01001101   →  0
00101000   →  3
1011 0000  →  4
00000000   →  8

Where count trailing zeros is used

Because it finds the lowest set bit in one step, ctz appears in many low-level routines.

  • Alignment checks. An address with 12 trailing zeros is aligned to 4,096 bytes.
  • Iterating over set bits: read the index with ctz, then clear that bit with x AND (x - 1).
  • The binary GCD algorithm, which strips common factors of two with shifts.
  • Bitboard move generation in chess engines, to find the next occupied square.
  • Sizing power-of-two buckets, where ctz of a size gives its exponent.

Input format and error message

Type the word using only 0 and 1. The tool lowercases the input, removes an optional 0b prefix and deletes all whitespace before scanning. Between 1 and 65,536 digits are accepted. Empty input, hex digits or any other character produce the error Enter between 1 and 65,536 binary digits.

Frequently asked questions

How many trailing zeros does 01100000 have?

Five. Reading from the right, there are five 0 bits before the first 1 appears. The value is 96, which is 32 times 3, and 32 is two to the fifth power.

What does the tool return for an input of all zeros?

It returns the number of digits entered, for example 8 for 00000000. This is the only situation in which the width of the word affects the answer.

Is the trailing zero count the same as the lowest set bit position?

Yes, for any word that contains a 1. The First set bit Calculator on this site returns the same number in that case. For an all-zero word it prints No set bit, while this tool prints the word length.

How do trailing zeros relate to divisibility?

A binary number with k trailing zeros is divisible by 2^k and by no higher power of two. Shifting the number right by k positions removes those factors and leaves an odd number.

Does this count trailing zeros of a factorial or a decimal number?

No. It counts zero bits at the end of a binary word. Trailing zeros of a decimal number such as 100 factorial are a different problem based on factors of ten.

Do I need to pad the word to 32 bits?

No. Zeros added on the left never change the count unless the whole word is zero. Paste the value at whatever width you have.

Related tools