leadingZeros

leadingZeros(integer x) → integer zeros

Returns the number of leading 0 bits of the integer x, that is, the bits before its first 1 bit, starting from the most significant bit. The count is always done over the 64 bits of a signed integer: leadingZeros(8) returns 60, because 8 is written 1000 and occupies the 4 least significant bits out of 64.

Returns 64 when x* is 0, and 0 when *x is negative, since its sign bit is 1. For a positive number, leadingZeros(x) + bitLength(x) is always 64.

leadingZeros(0)    // 64: no bit set to 1
leadingZeros(1)    // 63
leadingZeros(8)    // 60: 1000 in binary
leadingZeros(255)  // 56: 11111111 in binary
leadingZeros(-1)   // 0: the sign bit is 1
Math.leadingZeros(0)    // 64: no bit set to 1
Math.leadingZeros(1)    // 63
Math.leadingZeros(8)    // 60: 1000 in binary
Math.leadingZeros(255)  // 56: 11111111 in binary
Math.leadingZeros(0)    # 64: no bit set to 1
Math.leadingZeros(1)    # 63
Math.leadingZeros(8)    # 60: 1000 in binary
Math.leadingZeros(255)  # 56: 11111111 in binary
Parameters
Return
Note