13 lines
407 B
Text
13 lines
407 B
Text
// stream of numBits sized ints to bytes, numBits<8
|
|
fcn toBytes(n,[(numBits,acc,bitsSoFar)]state){
|
|
acc=acc.shiftLeft(numBits) + n; bitsSoFar+=numBits;
|
|
reg r;
|
|
if(bitsSoFar>=8){
|
|
bitsSoFar-=8;
|
|
r=acc.shiftRight(bitsSoFar);
|
|
acc=acc.bitAnd((-1).shiftLeft(bitsSoFar).bitNot());
|
|
}
|
|
else r=Void.Skip; // need more bits to make a byte
|
|
state.clear(numBits,acc,bitsSoFar);
|
|
r
|
|
}
|