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