MSB detector

The MSB detector reports the index of the most-significant bit that is set to 1 in the input bus, together with an enable flag that is high only when at least one bit is set. Scanning from the top, it locates the leading one, which is the classic priority function used for normalization and magnitude estimation.

Basic

Leading-one on 4 bits

For input 0110 the highest set bit is at index 2, so the detector outputs 2 and raises enable. When the input is 0000 there is no set bit, so enable stays low and the index is undefined.

InputEnableIndex
00000-
000110
001011
010012
011012
100013
Intermediate

Scanning a wider word

On an 8-bit input the detector still returns the position of the first 1 seen from the most-significant end. For 00101101 the leading one sits at index 5. This is equivalent to a count-leading-zeros minus one operation.

Scanning a wider word
Advanced

Floating-point normalization

Normalizing a value means shifting its most-significant one into a fixed position. The MSB index gives the shift amount directly, which is why hardware count-leading-zero units drive float normalizers, priority arbiters and log2 estimators.

Floating-point normalization

Citations

  • Shannon, C. E. (1938). A symbolic analysis of relay and switching circuits. Reference 1
  • Mano, M. M., & Ciletti, M. D. (2018). Digital design: With an introduction to the Verilog HDL, VHDL, and SystemVerilog (6th ed.). Pearson.
  • Wakerly, J. F. (2018). Digital design: Principles and practices (5th ed.). Pearson.