warp.bit\_count =============== .. currentmodule:: warp._src.lang .. function:: bit_count(x: Int) -> int32 .. wp-function-tags:: :kernel: true :python: true :differentiable: false Return the number of set bits in an integer. Signed inputs use their two's-complement representation, including the sign bit. In contrast, Python's ``int.bit_count()`` counts set bits in the absolute value, so the results can differ for negative inputs. :param x: A signed or unsigned scalar integer of 8, 16, 32, or 64 bits. Python ``int`` inputs are treated as ``int32``. :returns: The number of set bits in the fixed-width binary representation of ``x``. .. rubric:: Example >>> wp.bit_count(45) 4 >>> wp.bit_count(wp.int8(-1)) 8 >>> wp.bit_count(wp.int64(-1)) 64 >>> (-1).bit_count() # Python counts bits in the absolute value. 1