How do you know if a particular bit is set in dart?
example how to do this?
int value = 5;
if(checkBit(value, 4)) {
print("position: 4 TRUE");
} else {
print("position: 4 FALSE");
}
How do you know if a particular bit is set in dart?
example how to do this?
int value = 5;
if(checkBit(value, 4)) {
print("position: 4 TRUE");
} else {
print("position: 4 FALSE");
}
The solution is the same as @MihaiBC points to but since that is in C#, I am still going to post this just so we also have a Dart example:
void main() {
const value = 5;
print(value.toRadixString(2).padLeft(64, '0'));
// 0000000000000000000000000000000000000000000000000000000000000101
print(checkBit(value, 0)); // true
print(checkBit(value, 1)); // false
print(checkBit(value, 2)); // true
print(checkBit(value, 3)); // false
}
bool checkBit(int value, int bit) => (value & (1 << bit)) != 0;