31
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill rodydavis/skills --skill dart_bitwise- SKILL.md2.6 KB
Overview
This skill explains how to perform bitwise operations in Dart for both int and bool types. It covers AND, inclusive OR, exclusive OR (XOR), and their negated forms: NAND, NOR, and XNOR. Practical code examples show the equivalent behavior for integer bits and boolean logic. The goal is a concise reference you can copy into small programs or tests.
How this skill works
The guide shows how Dart applies bitwise operators to integers (using &, |, ^, ) and how logical equivalents work with booleans (&, |, ^ and !). For negated operations (NAND, NOR, XNOR) it demonstrates combining operators with bitwise complement () for ints and logical not (!) for bools. Examples include single-bit integer expressions (0/1) and direct boolean expressions to illustrate identical truth tables.
When to use it
- When manipulating individual bits or flags in integer values.
- When implementing low-level algorithms that rely on bit patterns (masks, toggles, merges).
- When you need boolean logic equivalents expressed with bitwise operators for performance or clarity.
- When teaching or testing truth tables for AND, OR, XOR and their negations.
- When porting bitwise logic between languages and verifying behavior with 0/1 int samples.
Best practices
- Use int bitwise operators (&, |, ^, ~) for bit-level arithmetic and masking.
- Use boolean forms (&, |, ^, !) when working with logical values to keep intent clear.
- For NAND/NOR/XNOR prefer explicit negation (e.g., !(a & b) or ~(a & b) & 1) to avoid subtle precedence bugs.
- When working with integers, mask results with & 1 if you only care about the lowest bit after a complement.
- Add comments for non-obvious uses of bitwise logic to improve readability and maintainability.
Example use cases
- Combining feature flags stored as bits in an int using | and checking flags with &.
- Toggling or clearing specific bits in configuration values with ^ and & plus masks.
- Implementing truth-table based conditions or simple digital-logic simulations using booleans or 0/1 ints.
- Creating parity checks or simple checksums using XOR across bits.
- Expressing NAND/NOR/XNOR gates in unit tests to validate logical circuits or algorithms.
FAQ
Yes. Dart overloads & | ^ for both int (bitwise) and bool (logical) contexts. The meaning depends on the operand types.
How do I get a single-bit result after using ~ (complement) on an int?
Mask the result with & 1 to isolate the least significant bit, for example: (~(a & b)) & 1.