Binary number
-It is a number which expressed in the base-2 numeral system,
-Binary numbers is 0 or 1
Hexadecimal number
- A number which expressed in the base-16 numeral system.
- Octal number range is 0 to 15
Conversion of binary to Hexadecimal-
Example -
Binary number is 101010
Its hexadecimal equivalent 2A
Binary number is 11111111
Its Hexadecimal equivalent is FF
program -
print("Enter Binary number")
n=int(input())
def func(n):
s=0
i=0
while(n):
t=n%10
s=s+t*(2**i)
n=int(n/10)
i=i+1
return s
s=""
while(n>0):
t=n%10000
t=func(t)
if t==10:
t="A"
if t==11:
t="B"
if t==12:
t="C"
if t==13:
t="D"
if t==14:
t="E"
if t==15:
t="F"
s=s+str(t)
n=int(n/10000)
s=str(s)
s=s[::-1]
print("Hexadecimal equivalent is - "+str(s))
Enter Binary number
11111111
Hexadecimal equivalent is - FF
Enter Binary number
100010001001
Hexadecimal equivalent is - 889
-In this program, Func() function is find the decimal equivalent of the four digit of the given binary number, then we combine all decimal equivalent together and print in reverse order.