Skip to content

Commit 2fa0740

Browse files
Merge pull request #2125 from pavitrachavda97/second
Adding hexCalculator project
2 parents 9cdbdad + bd271bc commit 2fa0740

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

hexCalculator/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Decimal To Hexadecimal
2+
3+
The aim of a decimal to hexadecimal (hex) calculator is to provide a tool that allows users to convert decimal numbers into their equivalent hexadecimal representation.
4+
5+
Decimal to hexadecimal calculator takes a decimal number as input and converts it into a hexadecimal number.
6+
The following steps are involved in the conversion process:
7+
- User input
8+
- Validation
9+
- Conversion algorithm
10+
- Hexadecimal Output
11+
12+
## Language
13+
- [x] Python
14+
15+
## Setup instructions
16+
Run the below command to show output
17+
```
18+
python hexCalculator.py
19+
```
20+
21+
## Output
22+
```
23+
Enter decimal value: 10
24+
Decimal Value: 10
25+
Hexadecimal Value: A
26+
```
27+
```
28+
Enter decimal value: 50
29+
Decimal Value: 50
30+
Hexadecimal Value: 32
31+
```

hexCalculator/hexCalculator.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
conversion_table = {0: '0', 1: '1', 2: '2', 3: '3', 4: '4',
2+
5: '5', 6: '6', 7: '7',
3+
8: '8', 9: '9', 10: 'A', 11: 'B', 12: 'C',
4+
13: 'D', 14: 'E', 15: 'F'}
5+
6+
def decimalToHexadecimal(a):
7+
b = ''
8+
while(a > 0):
9+
remainder = a % 16
10+
b = conversion_table[remainder] + b
11+
a = a // 16
12+
13+
return b
14+
15+
decimal = int(input("Enter decimal value: "))
16+
hexadecimal = decimalToHexadecimal(decimal)
17+
18+
print("Decimal Value:", decimal)
19+
print("Hexadecimal Value:", hexadecimal)

0 commit comments

Comments
 (0)