de2bi — Convert nonnegative decimal integers to binary or base-p digit rows in MATLAB and RunMat.

de2bi(D) converts decimal integers to rows of binary digits. Matrix inputs are converted in column-major D(:) order. Omitted width uses the minimum number of columns needed for the largest input. de2bi(D, N, P, FLG) selects the width, base, and digit ordering.

Syntax

de2bi(D)

How de2bi works

  • D may be a scalar, vector, logical array, or numeric matrix; matrix inputs are flattened in column-major order.
  • D values must be finite nonnegative integers in RunMat's exact integer range.
  • N specifies the number of output digit columns. If N is omitted or [], RunMat chooses the minimum width needed for the maximum input value.
  • If a supplied N is too small to represent an input value in base P, RunMat raises an error.
  • P must be an integer greater than one and defaults to 2.
  • 'right-msb' is the default and stores the least significant digit in column 1.
  • 'left-msb' stores the most significant digit in column 1.

Examples

Minimum-width binary expansion

b = de2bi([0; 1; 2; 5])

Expected output:

b = [0 0 0; 1 0 0; 0 1 0; 1 0 1]

Fixed-width left-MSB binary expansion

b = de2bi(5, 4, 'left-msb')

Expected output:

b = [0 1 0 1]

Base-3 expansion

b = de2bi(21, 4, 3, 'left-msb')

Expected output:

b = [0 2 1 0]

Using de2bi with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how de2bi changes the result.

Run a small de2bi example, explain the result, then change one input and compare the output.

FAQ

How does de2bi choose the number of columns?

When N is omitted, RunMat chooses the minimum width required by the largest input value in the selected base, with zero represented using one digit.

Can I pass a base without a width?

Yes. Use an empty width placeholder, for example de2bi(D, [], 3).

Conversion

bi2de · bin2dec · dec2bin · dec2hex · hex2dec

Modulation

pskmod · qammod

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how de2bi is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.