82. Python Program to Convert Decimal number into Hexadecimal number.
How does this program work?
- This program is used to convert given Decimal number into equivalent of Hexadecimal number using Python.
- That means convert number with base value 10 to base value 16.
- The integer entered by user will store in one variable. Divide that number by 16.
- Store the remainder when the number is divided by 2 in an array.
- If the remainder will less than 10 then we can add 48 to the remainder else we can add 55 to the remainder.
Here is the code
def decToHexa(n):
num = ['0'] * 100;
i = 0;
while(n != 0):
temp = 0;
temp = n % 16;
if(temp < 10):
num[i] = chr(temp + 48);
i = i + 1;
else:
num[i] = chr(temp + 55);
i = i + 1;
n = int(n / 16);
j = i - 1;
while(j >= 0):
print((num[j]), end = "")
j = j - 1;
n = int(input( "Enter an integer number: "));
print("The equivalent Hexadecimal number is : ",end='')
decToHexa(n)