export class BitWriter { value = 0 ; constructor ( private bitLength ) { } set ( size , startIndex , value ) { value &= ( 1 << size ) - 1 ; this . value |= value << ( this . bitLength - size - startIndex ) ; return this ; } } export function getBit ( bits , startIndex , length = 1 ) { let bin = bits . toString ( 2 ) . split ( "" ) ; bin = [ ... Array ( 8 - bin . length ) . fill ( "0" ) , ... bin ] ; const s = bin . slice ( startIndex , startIndex + length ) . join ( "" ) ; const v = parseInt ( s , 2 ) ; return v ; }