We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1da3875 + aa8eb5e commit 6f17fd3Copy full SHA for 6f17fd3
Decimal to binary/2to00000010.py
@@ -0,0 +1,30 @@
1
+# this uses GPL V3 LICENSE
2
+# code by @JymPatel
3
+
4
+import sys
5
6
+binary = '$' # just starting var
7
+n = 15 # can get 2**16 numbers
8
9
+# get integer as output which is less than limit 2**16
10
+try:
11
+ input = int(input("What is your Decimal Number?"))
12
+ limit = 2**(n + 1)
13
+ input <= limit
14
+except ValueError:
15
+ print("Please put integer in input! & less than", limit)
16
+ sys.exit()
17
18
+# main algorithm
19
+while n >= 0:
20
+ if input < 2**n:
21
+ binary = binary + '0'
22
+ else:
23
+ binary = binary + '1'
24
+ input = input - 2**n
25
+ n = n - 1
26
27
+print(binary)
28
29
+# get it at https://github.com/JymPatel/Python3-FirstEdition
30
+print("get it at https://github.com/JymPatel/Python3-FirstEdition")
0 commit comments