bitand — Compute bitwise AND for integer-valued scalars and arrays.
bitand(A, B) applies bitwise AND to finite nonnegative integer-valued inputs using MATLAB-style implicit expansion.
Syntax
C = bitand(A, B)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | NumericArray | Yes | — | Left integer-valued input. |
B | NumericArray | Yes | — | Right integer-valued input. |
Returns
| Name | Type | Description |
|---|---|---|
C | NumericArray | Bitwise numeric result. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:bitwise:InvalidInput | Inputs are not finite integer-valued numeric, logical, or gatherable gpuArray values. | bitwise operation: invalid input |
RunMat:bitwise:SizeMismatch | Input shapes are not compatible for implicit expansion. | bitwise operation: array sizes are not compatible |
RunMat:idivide:DivideByZero | The divisor contains zero. | idivide: division by zero |
RunMat:idivide:Overflow | A rounded quotient cannot be represented in the dividend integer class. | idivide: quotient overflows output class |
How bitand works
- Accepts double integer-valued inputs, logical inputs, integer scalar values, integer-class tensors, and gatherable gpuArray tensors.
- Supports implicit expansion across compatible shapes.
- For mixed unsigned integer inputs, returns the widest unsigned integer class involved; double and logical inputs return double-compatible numeric results.
- Rejects fractional, negative double, infinite, NaN, complex, string, cell, and struct inputs.
Does RunMat run bitand on the GPU?
RunMat currently executes integer bitwise functions on the host.
GPU memory and residency
GPU inputs are gathered for host execution.
Example
Scalar bitwise AND
bitand(6, 3)Expected output:
ans = 2Using bitand with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how bitand changes the result.
Run a small bitand example, explain the result, then change one input and compare the output.
FAQ
Can bitand broadcast scalar masks?⌄
Yes. Scalar masks expand across array inputs using MATLAB-compatible implicit expansion.
Related Logical functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how bitand is executed, line by line, in Rust.
- View the source for bitand 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.