Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd271bc

Browse files
Adding hexCalculator project
1 parent 7cd99a7 commit bd271bc

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)

AltStyle によって変換されたページ (->オリジナル) /