Skip to content

Commit 163a4d1

Browse files
First Commit
This is the simplest technique to convert decimal to binary.
1 parent 8f92c4f commit 163a4d1

File tree

1 file changed

+2
-30
lines changed

1 file changed

+2
-30
lines changed

Decimal to binary/2to00000010.py

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,2 @@
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")
1+
n=int(input("Enter the number in decimal : "))
2+
print(int((bin(n)[2:])))

0 commit comments

Comments
 (0)