Skip to content

Commit

Permalink
Merge pull request #336 from QunaSys/parity_sign_of_bits_ver2
Browse files Browse the repository at this point in the history
change parity_sign_of_bits
  • Loading branch information
toru4838 authored May 14, 2024
2 parents 7631626 + 732f2ee commit 4854de4
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions packages/core/quri_parts/core/utils/bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,4 @@ def lowest_bit_index(x: int) -> int:

def parity_sign_of_bits(bits: int) -> int:
"""Returns a sign corresponding to parity of bits (even=1, odd=-1)."""
sign = 1
for _ in range(bit_length(bits)):
if bits & 1 == 1:
sign *= -1
bits = bits >> 1
return sign
return 1 - 2 * (bin(bits).count("1") % 2)

1 comment on commit 4854de4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.