Skip to content

Commit

Permalink
Merge pull request #1437 from JymPatel/patch-1
Browse files Browse the repository at this point in the history
Create 2to00000010.py
  • Loading branch information
geekcomputers authored Nov 24, 2021
2 parents 1da3875 + aa8eb5e commit 6f17fd3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Decimal to binary/2to00000010.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# this uses GPL V3 LICENSE
# code by @JymPatel

import sys

binary = '$' # just starting var
n = 15 # can get 2**16 numbers

# get integer as output which is less than limit 2**16
try:
input = int(input("What is your Decimal Number?"))
limit = 2**(n + 1)
input <= limit
except ValueError:
print("Please put integer in input! & less than", limit)
sys.exit()

# main algorithm
while n >= 0:
if input < 2**n:
binary = binary + '0'
else:
binary = binary + '1'
input = input - 2**n
n = n - 1

print(binary)

# get it at https://github.com/JymPatel/Python3-FirstEdition
print("get it at https://github.com/JymPatel/Python3-FirstEdition")

0 comments on commit 6f17fd3

Please sign in to comment.