bitand — Compute bitwise AND for integer-valued scalars and arrays.
bitand(A, B) applies bitwise AND to same-class logical, integer, or finite nonnegative integer-valued double inputs using MATLAB-style implicit expansion. bitand(A, B, assumedtype) selects the signed or unsigned interpretation width for double inputs.
Syntax
C = bitand(A, B)
C = bitand(A, B, assumedtype)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | NumericArray | Yes | — | Left integer-valued input. |
B | NumericArray | Yes | — | Right integer-valued input. |
assumedtype | StringScalar | No | — | Integer class used to interpret double inputs. |
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 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 bitand works
- Accepts double integer-valued inputs, logical inputs, and all eight built-in integer classes.
- Supports implicit expansion across compatible shapes.
- Inputs must have the same data type unless one is a scalar double; the result has that shared type or the nondouble integer type.
- Logical inputs return logical output, integer inputs preserve their exact native class, and double inputs return double.
- Signed integer inputs and signed assumed types use two's-complement bit patterns.
- Rejects fractional, out-of-range, infinite, NaN, complex, mixed integer-class, string, cell, and struct inputs.
Does RunMat run bitand on the GPU?
The documented GPU domain accepts two unsigned integer arrays, or one unsigned integer array and one scalar double; 64-bit integers and assumedtype are unsupported.
RunMat mode separately gates single input, broader resident dtypes, and resident assumedtype calls as extensions.
GPU memory and residency
Documented uint8, uint16, and uint32 GPU inputs gather exactly for host execution and the result is restored to the owning provider.
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.