hex2dec

Converts hexadecimal text to a decimal number.

Category: Language Fundamentals > Data Types

Syntax

d = hex2dec(h)

Returns the value of the hexadecimal digits in h.

Description

Each string is read as a base-16 number. Because the result is a double, only values up to flintmax (2^53) are exact; use hex2num to read a 16-digit pattern as a floating-point number instead. The reverse conversion is dec2hex.

Input arguments

h
Character vector, string, or cell array of them; digits 0-9 and A-F, upper or lower case.

Output arguments

d
Double column: one value per input string.

Example

Hex to decimal

hex2dec('FF')
hex2dec('7fff')
hex2dec({'A'; '1F'; '100'})
Output
ans = 255
ans = 32767
ans = 3×1

    10
    31
   256

See also

dec2hex hex2num bin2dec dec2bin num2hex