bin2dec — Convert binary text to decimal numbers in MATLAB and RunMat.

bin2dec(binStr) converts binary character vectors, character matrices, string arrays, or cell arrays of text to decimal double values. Character matrix rows and cell text entries produce a column vector; string arrays preserve their shape.

Syntax

bin2dec(binStr)

How bin2dec works

  • Character vectors and string scalars produce a scalar double result.
  • Each row of a character matrix is converted independently.
  • String arrays preserve their input shape in the numeric output.
  • Cell arrays of character vectors or strings are converted element-by-element and returned as a column vector.
  • Optional 0b or 0B prefixes are accepted.
  • Unsigned suffixes u8, u16, u32, and u64 are accepted when the digits fit in the requested width.
  • Signed suffixes s8, s16, s32, and s64 interpret the digits as two's-complement signed values.
  • Results that exceed RunMat's exact integer range are rejected instead of silently losing precision.

Examples

Convert a binary character vector

d = bin2dec('10111')

Expected output:

d = 23

Convert rows of a character matrix

d = bin2dec(['1111111111'; '0001111010'; '0000001110'])

Expected output:

d = [1023; 122; 14]

Convert a string array and preserve its shape

d = bin2dec(["1111111111" "1111010" "1110"])

Expected output:

d = [1023 122 14]

Interpret a signed suffix

d = bin2dec('0b11111111s8')

Expected output:

d = -1

Using bin2dec with coding agents

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

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

FAQ

Can bin2dec parse prefixed binary literals?

Yes. RunMat accepts 0b and 0B prefixes.

What do signed suffixes mean?

A suffix such as s8 treats the parsed bits as a signed two's-complement integer with that width.

How does RunMat handle very large binary values?

RunMat returns double values only when the result is exactly representable; larger results raise an error instead of returning rounded values.

Conversion

bi2de · de2bi · dec2bin · dec2hex · hex2dec

Modulation

pskmod · qammod

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how bin2dec 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.