Skip to content

Modern Math LeadingZeros

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Math Library › Math Library › LeadingZeros

LeadingZeros

Counts the zero bits above the highest set bit; zero gives the type's full width.

Syntax

LeadingZeros( 0 )

Notes

  • returns the operand's FULL WIDTH

Examples

#import "std/numeric"
using numeric

'' How many zero bits before the highest set one
dim as uint32 x = 1
print LeadingZeros( x )      '' 31 -- in a 32-bit operand

dim as uint32 y = &hFFFFFFFF
print LeadingZeros( y )      '' 0

'' ZERO ANSWERS THE OPERAND'S FULL WIDTH, rather than being undefined
'' the way the raw CPU instruction is
dim as uint32 z = 0
print LeadingZeros( z )      '' 32

Library: Math Library
Category: Math Library
Documented under: Nothing Becomes A Keyword

Clone this wiki locally