September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
13
Task/Bitwise-IO/Zkl/bitwise-io-1.zkl
Normal file
13
Task/Bitwise-IO/Zkl/bitwise-io-1.zkl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// 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
|
||||
}
|
||||
7
Task/Bitwise-IO/Zkl/bitwise-io-2.zkl
Normal file
7
Task/Bitwise-IO/Zkl/bitwise-io-2.zkl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
ns:="THIS IS A TEST".pump(List,"toAsc",'-(0x20));
|
||||
ns.println(ns.len());
|
||||
|
||||
state:=L(6,0,0,L()); // input is six bits wide
|
||||
cns:=ns.pump(List,toBytes.fp1(state)); // List could be a file or socket or ...
|
||||
if(state[2]) cns+=toBytes(0,state); // flush
|
||||
cns.println(cns.len());
|
||||
12
Task/Bitwise-IO/Zkl/bitwise-io-3.zkl
Normal file
12
Task/Bitwise-IO/Zkl/bitwise-io-3.zkl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// stream of bytes to numBits sized ints, 1<numBits<32
|
||||
fcn fromBytes(n,[(numBits,acc,bitsSoFar,buf)]state){
|
||||
acc=acc.shiftLeft(8) + n; bitsSoFar+=8;
|
||||
buf.clear();
|
||||
while(bitsSoFar>=numBits){
|
||||
bitsSoFar-=numBits;
|
||||
buf.append(acc.shiftRight(bitsSoFar));
|
||||
acc=acc.bitAnd((-1).shiftLeft(bitsSoFar).bitNot());
|
||||
}
|
||||
state.clear(numBits,acc,bitsSoFar,buf);
|
||||
return(Void.Write,Void.Write,buf); // append contents of buf to result
|
||||
}
|
||||
4
Task/Bitwise-IO/Zkl/bitwise-io-4.zkl
Normal file
4
Task/Bitwise-IO/Zkl/bitwise-io-4.zkl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
state:=L(6,0,0,L()); // output is six bits wide
|
||||
r:=cns.pump(List,fromBytes.fp1(state)); // cns could be a file or ...
|
||||
r.println(r.len());
|
||||
r.pump(String,'+(0x20),"toChar").println();
|
||||
Loading…
Add table
Add a link
Reference in a new issue