bithacks

Creator: coderz1093

Last updated:

0 purchases

bithacks Image
bithacks Images

Languages

Categories

Add to Cart

Description:

bithacks

bithacks #
by Andrew Brampton (bramp.net)
Collection of bit twiddling hacks. Think
popcount or _pdep_u64.
Works on both Dart VM and dart2js.
GitHub | Package | API Docs
Usage #
// Count the number of bits set.
0.bitCount(); // returns 0
1.bitCount(); // returns 1
2.bitCount(); // returns 1
3.bitCount(); // returns 2
0x10101010.bitCount(); // returns 4

// Find the position of set bits. For example:
//
// 7 6 5 4 3 2 1 0 (index)
// 0 1 0 0 0 0 1 1 (value 0x43 with 3 bits set)
// 2 1 0 (rank)
//
0x43.bitRank(0); // returns 0 (found at index 0)
0x43.bitRank(1); // returns 1 (found at index 1)
0x43.bitRank(2); // returns 6 (found at index 6)
0x43.bitRank(3); // returns -1 (not found)
copied to clipboard
Development #
To run the tests:
dart test
dart test -p chrome
copied to clipboard
To publish:
dart analyze

# Bump the version in pubspec.yaml
dart pub lish
copied to clipboard
Additional information #
These algorithms were inspired by Bit Twiddling Hacks
by Sean Eron Anderson

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.