H
how-to-do-bitwise-operations-in-dart
About how-to-do-bitwise-operations-in-dart
This guide introduces bitwise operations on int and bool values for Dart developers. Examples cover AND, OR, XOR, and their negated forms.
Key features
- 01Explain bitwise operations on int
- 02Explain bitwise operations on bool
- 03Cover AND, OR, and XOR
- 04Describe NAND, NOR, and XNOR
- 05Provide Dart code examples
Use cases
- 01Look up Dart bitwise operator behavior
- 02Compare operations on integers and booleans
- 03Learn negated logical operations
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ rodydavis/ skills --skill how-to-do-bitwise-operations-in-dartAfter installing, type/how-to-do-bitwise-operations-in-dartin Claude Code to confirm it loaded.
Details
From the project READMEHow to do Bitwise operations in Dart
In Dart it is possible to do Bitwise Operations with int and bool types.
AND
Checks if the left and right side are both true. Learn more.
// int
print(0 & 1); // 0
print(1 & 0); // 0
print(1 & 1); // 1
print(0 & 0); // 0
// bool
print(false & true); // false
print(true & false); // false
print(true & true); // true
print(false & false); // false
OR
Inclusive
Checks if either the left or right side are true. Learn more.
// int
print(0 | 1); // 1
print(1 | 0); // 1
print(1 | 1); // 1
print(0 | 0); // 0
// bool
print(false | true); // true
print(true | false); // true
print(true | true); // true
print(false | false); // false
Exclusive
Checks if both the left or right side are true but not both. Learn more.
// int
print(0 ^ 1); // 1
print(1 ^ 0); // 1
print(1 ^ 1); // 0
print(0 ^ 0); // 0
// bool
print(false ^ true); // true
print(true ^ false); // true
print(true ^ true); // false
print(false ^ false); // false
NAND
Negated AND operation.
// int
print(~(0 & 1) & 1); // 1
print(~(1 & 0) & 1); // 1
print(~(1 & 1) & 1); // 0
print(~(0 & 0) & 1); // 1
// bool
print(!(false & true)); // true
print(!(true & false)); // true
print(!(true & true)); // false
print(!(false & false)); // true
NOR
Negated inclusive OR operation.
// int
print(~(0 | 1) & 1); // 0
print(~(1 | 0) & 1); // 0
print(~(1 | 1) & 1); // 0
print(~(0 | 0) & 1); // 1
// bool
print(!(false | true)); // false
print(!(true | false)); // false
print(!(true | true)); // false
print(!(false | false)); // true
XNOR
Negated exclusive OR operation.
// int
print(~(0 ^ 1) & 1); // 0
print(~(1 ^ 0) & 1); // 0
print(~(1 ^ 1) & 1); // 1
print(~(0 ^ 0) & 1); // 1
// bool
print(!(false ^ true)); // false
print(!(true ^ false)); // false
print(!(true ^ true)); // true
print(!(false ^ false)); // true
Comments
Markdown supported