dec2hex — Convert decimal integers to hexadecimal character rows in MATLAB and RunMat.
dec2hex(D) converts each element of D to one uppercase hexadecimal character row. dec2hex(D, minDigits) pads rows to at least minDigits characters. Numeric arrays are processed in column-major element order and produce one output row per element.
Syntax
dec2hex(D)How dec2hex works
Dmay be numeric, integer, logical, character, or gpuArray numeric data.- Double inputs must be finite integer values.
- Nonnegative values are padded with
0characters. - Negative values are represented using the smallest signed two's-complement storage width that can contain the value, with additional padding using
Fcharacters. - Signed integer inputs preserve their source integer storage width for negative two's-complement output.
minDigitsmust be a finite nonnegative integer scalar.- Outputs larger than RunMat's character-output safety limit are rejected before formatting.
- Complex, non-finite, fractional, and unsupported input values raise an error.
Examples
Convert a scalar decimal value
s = dec2hex(1023)Expected output:
s = '3FF'Pad to a minimum width
s = dec2hex(1023, 6)Expected output:
s = '0003FF'Convert multiple values to padded rows
s = dec2hex([1023 122 14])Expected output:
s = ['3FF'; '07A'; '00E']Format a negative value as two's complement
s = dec2hex(-16)Expected output:
s = 'F0'Using dec2hex with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how dec2hex changes the result.
Run a small dec2hex example, explain the result, then change one input and compare the output.
FAQ
Are fractional inputs accepted?⌄
No. RunMat requires finite integer values for dec2hex.
Are hexadecimal letters uppercase?⌄
Yes. RunMat emits uppercase A through F characters.
Related Comms functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how dec2hex is executed, line by line, in Rust.
- View the source for dec2hex in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.