Skip to content

Commit

Permalink
write function to convert an integer from decimal to binary in python
Browse files Browse the repository at this point in the history
  • Loading branch information
justanindieguy committed Feb 2, 2023
1 parent 75269d9 commit 31a39c0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Bit-manipulationTechniques/DecimalToBinary/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def convert_to_binary(n: int):
ans = 0
exp = 1

while n > 0:
ans += (n % 2) * exp
exp *= 10
n = n // 2

return ans


def main():
n = int(input())
print(convert_to_binary(n))


if __name__ == "__main__":
main()

0 comments on commit 31a39c0

Please sign in to comment.