How to resolve the algorithm Bitwise IO step by step in the PL/I programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Bitwise IO step by step in the PL/I programming language

Table of Contents

Problem Statement

language is Object Oriented and you prefer) for reading and writing sequences of bits, most significant bit first. While the output of a asciiprint "STRING" is the ASCII byte sequence "S", "T", "R", "I", "N", "G", the output of a "print" of the bits sequence 0101011101010 (13 bits) must be 0101011101010; real I/O is performed always quantized by byte (avoiding endianness issues and relying on underlying buffering for performance), therefore you must obtain as output the bytes 0101 0111 0101 0000 (bold bits are padding bits), i.e. in hexadecimal 57 50. As test, you can implement a rough (e.g. don't care about error handling or other issues) compression/decompression program for ASCII sequences of bytes, i.e. bytes for which the most significant bit is always unused, so that you can write seven bits instead of eight (each 8 bytes of input, we write 7 bytes of output). These bit oriented I/O functions can be used to implement compressors and decompressors; e.g. Dynamic and Static Huffman encodings use variable length bits sequences, while LZW (see LZW compression) use fixed or variable words nine (or more) bits long.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Bitwise IO step by step in the PL/I programming language

Source code in the pl/i programming language

declare onebit bit(1) aligned, bs bit (1000) varying aligned;
on endfile (sysin) go to ending;
bs = ''b;
do forever;
   get edit (onebit) (F(1));
   bs = bs || onebit;
end;
ending:
bs = bs || copy('0'b, mod(length(bs), 8) );
                                 /* pad length to a multiple of 8 */
put edit (bs) (b);

  

You may also check:How to resolve the algorithm Combinations with repetitions step by step in the Ursala programming language
You may also check:How to resolve the algorithm Rosetta Code/Count examples step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Numbers which are the cube roots of the product of their proper divisors step by step in the Julia programming language
You may also check:How to resolve the algorithm Ethiopian multiplication step by step in the OCaml programming language
You may also check:How to resolve the algorithm Population count step by step in the OCaml programming language