-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increased version number; created README
- Loading branch information
1 parent
3e2347a
commit 5191ed9
Showing
2 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# JavaScirpt Bit List | ||
- Bit list is a data structure which may be used to store arrays of boolean values in a number. This method allows such arrays to be used in places where the data shortness is important, e. g. in query string parameters. | ||
- This data structure plays with the binary representation of the numbers. Each element (named "bit") is just a bit of the number. To set the nth bit to true means to add pow(2, n) to the number, to set it to false means to subtract pow(2, n) from the number. | ||
## Examples | ||
```javascript | ||
// Import the class | ||
const BitList = require("js-bit-list"); | ||
// Create new bit list | ||
let list = new BitList(); | ||
// Add some values | ||
list.setBit(3, 1); | ||
list.setBit(4, 1); | ||
// Convert to number | ||
let num = list.toNumber(); // Gives 2**3 + 2**4 = 24 | ||
// Convert to array | ||
let arr = list.toArray(); // Gives [0, 0, 0, 1, 1] | ||
// Predefined values | ||
let predefinedList = new BitList([0, 0, 0, 1, 1, 0, 0]) | ||
let predefinedListFromNumber = new BitList(31); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters