bitset — Set or clear selected one-based bit positions.
C = bitset(A,bit) sets selected bits to one. C = bitset(A,bit,V) sets or clears them according to V. Scalar controls expand, while nonscalar inputs must have exactly matching sizes.
Syntax
C = bitset(A, bit)
C = bitset(A, bit, V)
C = bitset(A, bit, assumedtype)
C = bitset(A, bit, V, assumedtype)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | NumericArray | Yes | — | Integer-valued input. |
bit | NumericArray | Yes | — | One-based bit position. |
V | NumericArray | No | 1 | Zero clears the bit; any finite nonzero value sets it. |
assumedtype | StringScalar | No | — | Integer class used to interpret double input A. |
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 bitset works
- All eight native integer classes are supported and output preserves the class of A.
- Bit positions must be finite positive integers within the selected storage width.
- Replacement values must classify as zero or one.
- Only A selects GPU output ownership; bit and V are controls.
Using bitset with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how bitset changes the result.
Run a small bitset example, explain the result, then change one input and compare the output.
Related Logical functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how bitset is executed, line by line, in Rust.
- View the source for bitset 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.