dec2hex
Converts a nonnegative integer to hexadecimal text.
Category: Language Fundamentals > Data Types
Syntax
h = dec2hex(d)
Hexadecimal digits of d, using uppercase letters.
h = dec2hex(d, len)
Pads with zeros to at least len digits.
Description
Each hexadecimal digit stands for four bits, so dec2hex(255) is 'FF'. It is often used for colors and memory values. The reverse is hex2dec.
Input arguments
d- Nonnegative integers up to
flintmax. len- Minimum number of digits.
Output arguments
h- Char array, one row per element, padded with zeros to the same length.
Example
Single value and vector
dec2hex(255)
dec2hex(10, 4)
dec2hex([10 255 4096])
Output
ans = 'FF'
ans = '000A'
ans = 3×4 char array
'000A'
'00FF'
'1000'