➽ Program:-
binary_number
= int(input("Enter the Binary Number: "))
hexadecimal_number
= 0
hexadecimal_arr
= []
i = 0
product
= 1
temp
= 1
while
binary_number != 0:
rem = binary_number % 10
hexadecimal_number = hexadecimal_number +
(rem * product)
if temp %4 == 0:
if hexadecimal_number < 10:
hexadecimal_number =
hexadecimal_number + 48
value = chr(hexadecimal_number)
hexadecimal_arr.insert(i, value)
else:
hexadecimal_number =
hexadecimal_number + 55
value = chr(hexadecimal_number)
hexadecimal_arr.insert(i, value)
product = 1
hexadecimal_number = 0
temp = 1
i = i + 1
else:
product = product * 2
temp = temp + 1
binary_number = int(binary_number/10)
if
temp != 1:
hexadecimal_number = hexadecimal_number +
48
value = chr(hexadecimal_number)
hexadecimal_arr.insert(i, value)
if
temp == 1:
i = i-1
print("Hexadecimal
value is ", end="")
while
i >= 0:
print(end = hexadecimal_arr[i])
i = i-1
print()
➽ Output:-
0 Comments
Please do not enter any spam link in the comment section.