Skip to content

Commit 9545d43

Browse files
Merge pull request geekcomputers#206 from yadneshk/master
convert decimal to hexadecimal
2 parents 871432f + 42713f5 commit 9545d43

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

dec_to_hex.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
mydict={
2+
'0':'0','1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','7':'7','8':'8','9':'9','10':'A','11':'B',
3+
'12':'C','13':'D','14':'E','15':'F'
4+
}
5+
dec_num=input('Enter the decimal number\n');
6+
dec_num=int(dec_num)
7+
value=""
8+
while dec_num>0:
9+
value+=mydict[str(dec_num%16)]
10+
dec_num=dec_num//16
11+
hex_value=value[::-1]
12+
print(hex_value)

0 commit comments

Comments
 (0)