get value of bit in integer python
def is_set(x, n):
return x & 1 << n != 0
# 10 in binary is 1010, and since 0 indexed the 1st bit is 1 therefore returns True
is_set(10, 1)
# >>> True
get value of bit in integer python
def is_set(x, n):
return x & 1 << n != 0
# 10 in binary is 1010, and since 0 indexed the 1st bit is 1 therefore returns True
is_set(10, 1)
# >>> True
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us