top of page
Writer's pictureThe Tech Platform

Hex() function in Python

hex() function is one of the built-in functions in Python3, which is used to convert an integer number into it’s corresponding hexadecimal form.


Syntax :

hex(x) 

Parameters : x - an integer number (int object) Returns : Returns hexadecimal string.


Illustrates use of hex() function.


Example:

a = 2.8
x = 200
y = hex(x)
print("Hex() function")
print("The hexadecimal form of",x, "is", y , "\n")

print("Print ASCII Value" )
print("The hexadecimal form of the ascii value is 'b' is " + hex(ord('a')),"\n")

print("Print Hex() function Float ")
print("The hexadecimal form of", a, " is ", float.hex(a))

Output:


Applications :

hex() is used in all the standard conversions. For example conversion of hexadecimal to decimal, hexadecimal to octal, hexadecimal to binary.



The Tech Platform

0 comments

Comments


bottom of page