Dear comp.lang.python, When I asked ChatGPT how I would get the number of zero bits in a Python integer, it spouted some nonsense about calculating it with
( n & -n ).bit_length() - 1 but that hardly seems like the best way. Specifically, I'm trying to count the number of zero bits to the right of the rightmost one bit. The above formula seems to work, given a few spot checks, but I thought this should be a utility function in the underlying multiprecision lib- rary in Python. Is the calculation n & -n really necessary? What does the Lawrence D'Oliveiro say about this? -- Johann | email: invalid -> com | http://www.myrkraverk.com/blog/ I'm not from the Internet, I just work there. | via Easynews.com https://bsky.app/profile/myrkraverk.bsky.social | for ( ;; ) _:; -- https://mail.python.org/mailman3//lists/python-list.python.org
