-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1437 from JymPatel/patch-1
Create 2to00000010.py
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
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
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") |