num2hex

Hexadecimal text of the IEEE 754 bit pattern of a number.

Category: Language Fundamentals > Data Types

Syntax

S = num2hex(X)

Returns one row of hexadecimal digits for each element of X.

Description

The digits show how the number is stored in memory: a sign bit, an exponent field and the fraction bits. 1 in double precision is 3ff0000000000000, and -2 in single precision is c0000000. It is useful to inspect rounding behavior and special values such as NaN and Inf.

The inverse operation is hex2num.

Input arguments

X
Array of class double or single.

Output arguments

S
Char matrix with one row per element: 16 digits for double, 8 for single.

Example

num2hex(1)
num2hex(single(-2))
num2hex([1 2])
Output
ans = '3ff0000000000000'
ans = 'c0000000'
ans = 2×16 char array

    '3ff0000000000000'
    '4000000000000000'

See also

hex2num dec2hex dec2bin typecast eps