Skip to content

Commit 9453a8c

Browse files
basic maths python program
1 parent e025a97 commit 9453a8c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# decimal = 2
2+
# for conversion will use inbuilt functions
3+
#
4+
#
5+
# for i in range(0, 33):
6+
# print("the Octal value of",i,bin(i))
7+
8+
# print(bin(decimal))
9+
# print(oct(decimal))
10+
# print(hex(decimal))
11+
12+
# print(bin(0x2a))
13+
14+
# dec(bi)
15+
16+
def bin_to_decimal(num):
17+
decimal = 0
18+
temp = num
19+
count = 0
20+
while temp > 0:
21+
# print(num)
22+
digit = temp % 10 #temp=1011 -- chinu debugged
23+
decimal = decimal + digit * pow(2,count)
24+
temp = temp // 10
25+
count = count + 1
26+
return decimal
27+
28+
29+
def bin_to_decimal_int(num):
30+
return int(num, 2)
31+
32+
print(bin_to_decimal(1111))
33+
print(bin_to_decimal_int('1011'))

0 commit comments

Comments
 (0)