bi2de — Convert base-P digit rows to decimal values.
bi2de(B) interprets each row of a real numeric or logical digit array as one base-2 number. The first column holds the least significant digit by default. Specify a base P and/or 'left-msb' to change the interpretation.
Syntax
D = bi2de(B)
D = bi2de(B, flg)
D = bi2de(B, P)
D = bi2de(B, P, flg)Inputs
B- Type
Any- Required
- Yes
- Description
- Real numeric or logical digit row/vector/matrix.
flg- Type
StringScalar- Required
- Yes
- Default
'right-msb'- Description
- Digit order: right-msb or left-msb.
P- Type
NumericScalar- Required
- Yes
- Default
2- Description
- Integer base at least two.
Returns
D- Type
NumericArray- Description
- One decimal value for each digit row.
Errors
RunMat:bi2de:InvalidInput- When
- B is not a real numeric/logical 2-D digit array, or a digit is invalid.
- Message
bi2de: B must contain valid real digits
RunMat:bi2de:InvalidBase- When
- P is not an integer scalar at least two.
- Message
bi2de: P must be an integer greater than 1
RunMat:bi2de:InvalidOrder- When
- The digit order is not right-msb or left-msb.
- Message
bi2de: unsupported digit order
Digits, shape, and class
A row vector produces one scalar. Each row of a matrix produces one element of a column vector. The default base is two and the default order is 'right-msb'; 'left-msb' makes the first column most significant.
Digits must be finite nonnegative integers less than P. Results above 2^52 reject rather than pass through an inexact decimal conversion. Double and logical inputs produce double values; single input produces single. Integer input retains its class if the result fits and otherwise widens within the same signedness.
Execution
Digit validation and conversion run on the host; the operation is a fusion boundary and does not use a GPU kernel. RunMat mode can gather a GPU-resident digit matrix after admission. MATLAB-compatible mode rejects that form before provider access.
A fixed-width integer base P is a RunMat extension. MATLAB-compatible mode accepts the documented single/double numeric base. Neither form reads the workspace, invokes callbacks, performs I/O, nor depends on time or randomness.
Examples
Convert default right-MSB digits
d = bi2de([1 0 1 0])Expected output:
d = 5Read the first column as most significant
d = bi2de([1 0 1 0], 'left-msb')Expected output:
d = 10Convert two base-3 digit rows
d = bi2de([2 1 0; 0 1 2], 3, 'left-msb')Expected output:
d = [21; 5]Keep an integer result's class
d = bi2de(uint8([1 0 1]))Expected output:
d = uint8(5)Reject a digit outside the base
bi2de([1 2])Compile digit conversion and error handling
B = [1 0 1; 0 1 1]; D = bi2de(B); L = bi2de([1 0 1 0],'left-msb'); caught = false; try; bad = bi2de([1 2]); catch failure; caught = strcmp(failure.identifier,'RunMat:bi2de:InvalidInput'); endUsing bi2de with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how bi2de changes the result.
Run a small bi2de example, explain the result, then change one input and compare the output.
FAQ
What is the default digit ordering?⌄
'right-msb'. The first column is least significant unless you pass 'left-msb'.
Can bi2de convert bases other than two?⌄
Yes. Pass an integer base P of at least two, such as bi2de(B,3).
What happens if the decimal result is too large?⌄
The conversion rejects results above 2^52 rather than silently losing exactness.
Related Comms functions
Source you can read
Every RunMat function's source is public. Read exactly how bi2de is executed, line by line, in Rust.
- View the source for bi2de in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.