Skip to content

Instantly share code, notes, and snippets.

@s0ubhik
Created June 30, 2021 09:55
Show Gist options
  • Save s0ubhik/b971a6b79a02866d52e6154e6bbe0493 to your computer and use it in GitHub Desktop.
Save s0ubhik/b971a6b79a02866d52e6154e6bbe0493 to your computer and use it in GitHub Desktop.
Python function to convert integer to Binary String
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