Bitwise IO: Difference between revisions

Replace deprecated functions
m (→‎{{header|11l}}: `read_bytes_at_most(n)` -> `read_bytes(at_most' n)`)
(Replace deprecated functions)
 
Line 3,486:
}</syntaxhighlight>
=={{header|Seed7}}==
The Seed7 library [httphttps://seed7.sourceforge.net/libraries/bitdata.htm bitdata.s7i] defines
several functions to do bitwise I/O. Bitwise data can be read from (or written to) a string or a file.
The direction of bits can be from LSB (least significant bit) to MSB (most significant bit) or vice versa.
In the program below the functions
[httphttps://seed7.sourceforge.net/libraries/bitdata.htm#putBitsMsb(inout_file,inout_integer,in_var_integer,in_var_integer) putBitsMsb], [https://seed7.sourceforge.net/libraries/bitdata.htm#openMsbBitStream(in_file) openMsbBitStream] and [httphttps://seed7.sourceforge.net/libraries/bitdata.htm#getBitsMsbgetBits(inout_fileinout_msbBitStream,inout_integer,in_var_integerin_integer) getBitsMsbgetBits] are used.
 
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
Line 3,517:
const proc: finishWriteAscii (inout file: outFile, inout integer: bitPos) is func
begin
putBitsMsb(outFile, bitPos, 0, 7); # Write a terminating NUL char.
write(outFile, chr(ord(outFile.bufferChar)));
end func;
 
const procfunc string: initReadAsciireadAscii (inout file: outFile, inout integermsbBitStream: bitPosaBitStream) is func
begin
bitPos := 8;
end func;
 
const func string: readAscii (inout file: inFile, inout integer: bitPos, in integer: length) is func
result
var string: stri is "";
Line 3,531 ⟶ 3,527:
var char: ch is ' ';
begin
while not eof(inFile) and length(stri)ch <> length'\0;' do
ch := chr(getBitsMsbgetBits(inFile, bitPosaBitStream, 7));
if inFile.bufferCharch <> EOF'\0;' then
stri &:= ch;
end if;
Line 3,543 ⟶ 3,539:
var file: aFile is STD_NULL;
var integer: bitPos is 0;
var msbBitStream: aBitStream is msbBitStream.value;
begin
aFile := openStrifileopenStriFile;
initWriteAscii(aFile, bitPos);
writeAscii(aFile, bitPos, "Hello, Rosetta Code!");
finishWriteAscii(aFile, bitPos);
seek(aFile, 1);
initReadAsciiaBitStream := openMsbBitStream(aFile, bitPos);
writeln(literal(readAscii(aFile, bitPos, 100aBitStream)));
end func;</syntaxhighlight>
 
Line 3,557 ⟶ 3,554:
"Hello, Rosetta Code!"
</pre>
 
=={{header|Tcl}}==
<syntaxhighlight lang="tcl">package require Tcl 8.5
29

edits