on writing a number as 2^s * q, where q is odd

Alan Bawden alan at csail.mit.edu
Wed Nov 29 21:34:58 EST 2023


Julieta Shem <jshem at yaxenu.org> writes:

   How would you write this procedure?
   def powers_of_2_in(n):
       ...

def powers_of_2_in(n):
    return (n ^ (n - 1)).bit_count() - 1


More information about the Python-list mailing list