Skip to content

Latest commit

 

History

History
15 lines (13 loc) · 418 Bytes

README.md

File metadata and controls

15 lines (13 loc) · 418 Bytes

bit-prefix-len

Returns the bit prefix length of a buffer -- the number of consecutive 0s or 1s. This is useful for all sorts of crypto things.

> var bitPrefixLen = require('bit-prefix-len')
> bitPrefixLen(0, new Buffer('0000abc00abc', 'hex'))
16
> bitPrefixLen(0, new Buffer('800000000000', 'hex'))
0
> bitPrefixLen(1, new Buffer('fffffffffffe', 'hex'))
47
> bitPrefixLen(1, new Buffer('ff00', 'hex'))
8