RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • and
    • bitand
    • bitcmp
    • bitget
    • bitor
    • bitset
    • bitshift
    • bitxor
    • not
    • or
    • xor

bitshift — Shift integer-valued scalars and arrays left or right by bit counts.

bitshift(A, k) shifts integer-valued input A left for positive k and right for negative k. A and k must be scalar or exactly the same size; bitshift(A, k, assumedtype) selects the signed or unsigned interpretation width for double A.

Syntax

C = bitshift(A, K)
C = bitshift(A, K, assumedtype)

Inputs

NameTypeRequiredDefaultDescription
ANumericArrayYes—Integer-valued input.
KNumericArrayYes—Shift count; positive shifts left and negative shifts right.
assumedtypeStringScalarNo—Integer class used to interpret double input A.

Returns

NameTypeDescription
CNumericArrayBitwise numeric result.

Errors

IdentifierWhenMessage
RunMat:bitwise:InvalidInputInputs are not finite integer-valued numeric, logical, or gatherable gpuArray values.bitwise operation: invalid input
RunMat:bitwise:SizeMismatchInput shapes violate the operation's expansion rule: binary bitwise functions use compatible-size expansion, while bit positions/counts require scalar expansion or exactly matching nonscalar sizes.bitwise operation: array sizes are not compatible

How bitshift works

  • A accepts double and all eight built-in integer classes; k independently accepts double and all eight integer classes.
  • Positive shifts move bits left and truncate overflow bits; negative shifts move bits right and preserve the sign bit for signed A.
  • Shift magnitudes at least the width of A produce zero, except a negative shift of negative signed A produces all one-bits.
  • Output preserves the data type of A; the class of k does not affect output class.
  • Rejects fractional, infinite, NaN, complex, logical, single, string, cell, struct, and nonscalar unequal-size inputs in MATLAB-compatible mode.

Does RunMat run bitshift on the GPU?

At least one input must be an integer array, A cannot be signed, 64-bit integers are unsupported in either input, and assumedtype is unsupported.

RunMat mode separately gates single A, single k, logical A, logical k, broader resident input combinations, and resident assumedtype calls as extensions.

GPU memory and residency

Documented GPU calls gather exactly for host execution and restore the output class of A to the owning provider.

Example

Left and right shifts

bitshift(uint32(3), 2)
bitshift(uint32(8), -1)

Expected output:

ans = uint32
  12
ans = uint32
  4

Using bitshift with coding agents

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

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

FAQ

Can shift counts be arrays?⌄

Yes. A and k can each be scalar, or they can be arrays with exactly the same size; general singleton expansion is not supported.

Related Logical functions

Bit

and · bitand · bitcmp · bitget · bitor · bitset · bitxor · not · or · xor

Tests

allfinite · isfinite · isgpuarray · isinf · islogical · isnan · isnumeric · isreal · issparse

Rel

eq · ge · gt · isequal · isequaln · le · lt · ne

Logical

logical

Open-source implementation

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

  • View the source for bitshift 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.

Getting started · Benchmarks · Pricing

Download RunMat

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

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How bitshift works
  • Does RunMat run bitshift on the GPU?
  • GPU memory and residency
  • Example
  • Left and right shifts
  • Using bitshift with coding agents
  • FAQ
  • Related Logical functions
  • Bit
  • Tests
  • Rel
  • Logical
  • Open-source implementation
  • About RunMat