Created
June 30, 2021 09:55
-
-
Save s0ubhik/b971a6b79a02866d52e6154e6bbe0493 to your computer and use it in GitHub Desktop.
Python function to convert integer to Binary String
This file contains 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 IntToBin(num): | |
bin_str = "" | |
while num > 0: | |
if num % 2 == 0: # num is even | |
bin_str = "0" + bin_str | |
else: # num is odd | |
bin_str = "1" + bin_str | |
num -= 1 | |
num = num / 2 | |
return bin_str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment