How to get the hexadecimal value of a float number in python?

Python | find hexadecimal value of float value: Here, we are going to learn how to find a hexadecimal value of a given float value? Submitted by IncludeHelp, on April 03, 2019

Hexadecimal value of a float number

To get the hexadecimal value of a float number we use – float.hex() method, it accepts a float value and returns its hexadecimal value in string format.

Syntax

float.hex(number)

Parameter(s)

number – a float value to be converted into hexadecimal.

Return value

str – it returns hexadecimal value of number in string format.

Example

Input:
num = 10.23
    
print("hex value of ", num, " is = ", float.hex(num))
    
Output:
hex value of  10.23  is =  0x1.475c28f5c28f6p+3

Python code to get hexadecimal value of given float number

# python code to demonstrate example
# of float.hex() function

num = 0.0
print("hex value of ", num, " is = ", float.hex(num))

num = 10.23
print("hex value of ", num, " is = ", float.hex(num))

num = -10.23
print("hex value of ", num, " is = ", float.hex(num))

Output

hex value of  0.0  is =  0x0.0p+0
hex value of  10.23  is =  0x1.475c28f5c28f6p+3
hex value of  -10.23  is =  -0x1.475c28f5c28f6p+3

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.