Created
December 29, 2016 17:04
-
-
Save marcouberti/18daf5ec445bfee8154d2481bcc7389d to your computer and use it in GitHub Desktop.
Find LSB and MSB bit in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bits_converter(x): | |
index = 0 | |
bits = "" | |
while x is not 0: | |
bits += str(x & 1) | |
x = x >> 1 | |
index+=1 | |
return bits[::-1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lsb(x): | |
return x & 1 | |
def lsb_alternative(x): | |
return x % 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment