hex2num

Converts a hexadecimal bit pattern to a floating-point number.

Category: Language Fundamentals > Data Types

Syntax

x = hex2num(h)

Reads h as the IEEE 754 double-precision bits of a number.

Description

The 16 hex digits give the sign, exponent and fraction fields of a double. For instance 3ff0000000000000 is 1, and c000000000000000 is -2. This lets you build exact special values or inspect rounding. The reverse conversion is num2hex.

Input arguments

h
Character vector or string of up to 16 hex digits. Shorter text is padded with zeros on the right.

Output arguments

x
Double value whose 64-bit representation is h.

Example

Bit patterns

hex2num('3ff0000000000000')
hex2num('3ff8000000000000')
hex2num('c000000000000000')
Output
ans = 1
ans = 1.5000
ans = -2

See also

num2hex hex2dec dec2hex typecast eps