A new command/active function is needed to convert pl1 bit string data between radixes (binary, quaternary, octal or hexadecimal), and to adjust bit string length and output format.
Documentation for the proposed program is shown below.
h bit_string -all
>user_dir_dir>Multics>GDixon>work>ect>bit_string.info (156 lines in info)
2025-03-05 bit_string, bit
Syntax as a command:
bit INPUT_STR {-control_args}
Syntax as an active function:
[bit INPUT_STR {-control_args}]
Function:
This command or active function accepts a character representation of a
pl1 bit string as an input value.
The program converts INPUT_STR to an actual bit string using either its
ending radix indicator or the -in control argument to specify how to
interpret characters of INPUT_STR.
By default, the result bit string is displayed or returned as a pl1
quoted bit string with a binary radix factor: "10011"b
Arguments:
INPUT_STR
is the character representation of the input bit string. It may end
with one of the radix indicators shown below.
INDICATOR Description
------------- -------------------------------------------------
b or _b or b1 INPUT_STR is binary characters from 0 thru 1
q or _q or b2 INPUT_STR is quaternary characters from 0 thru 3
o or _o or b3 INPUT_STR is octal characters from 0 thru 7
x or _x or b4 INPUT_STR is hexadecimal characters from 0 thru f
in upper- or lower-case.
The b4 indicator may be used only if INPUT_STR has double-quote (")
characters surrounding the numeric digits. Without these quotes,
the b4 radix_indicator would be treated as digits in the INPUT_STR
string.
Control arguments:
-in RADIX_INDICATOR
controls how characters of INPUT_STR are interpreted, unless that
string ends with its own radix_indicator substring. An indicator
can specify binary, quaternary, octal or hexadecimal characters in
the INPUT_STR. See the "List of radix_indicator substrings" section
for details. (default: octal input)
-out RADIX_INDICATOR
displays or returns the result bit string as a character string
using characters of one of the power-of-2 bases. See the
"List of radix_indicator substrings" section for details.
(default: binary output)
-length L, -ln L
gives a desired bit length for the resulting bit string. By
default, each INPUT_STR character is converted to B-bits according
to its designated input radix:
Radix B
----------- --------------------
binary 1 bit per character
quaternary 2 bits per character
octal 3 bits per character
hexadecimal 4 bits per character
Result default length D = B * length(INPUT_STR). If INPUT_STR ends
with its own radix_indicator substring, that substring is excluded
from the length(INPUT_STR) determination.
If L is greater than the default length D, then L-D zero bits are
appended to the right end of the result. If L is less than the
default length D, then D-L bits are removed from the right end of
the result.
-quote, -q
display or return the result as a pl1 quoted bit string with
trailing radix factor. (default) For example:
"1011"b or "23"b2 or "54"b3 or "b"b4
-no_quote, -nq
display or return the result as a character string without
surrounding quote characters or pl1 radix factor:
1011 or 23 or 54 or b
-radix
display or return the result as a character string without
surrounding quote characters but with a radix indicator:
1011_b or 23_q or 54_o or b_x
List of radix_indicator substrings:
INPUT_STR may end with one of the following strings which indicate
which numbering system's digits are expressing the value.
Indicator characters may also be given in uppercase. -in and -out
may be followed by any of the values below; but values beginning
with underscore (_) are not usually given with these -control_args.
b1, b, _b
the number is interpreted as a base two string (binary).
b2, q, _q
the number is interpreted as a base four string (quaternary).
b3, o, _o
the number is interpreted as a base eight string (octal).
b4, x, _x
the number is interpreted as a base sixteen string (hexadecimal).
The b4 format may be used only if INPUT_STR has double-quote (")
characters surrounding the numeric digits. Without these quotes,
the b4 radix factor would be treated as digits in the INPUT_STR
string.
Notes:
To express a result bit string in a non-binary radix, each output digit
represents a group of B-bits in the result (where B is 2, 3, or 4). If
the length of the result is not evenly divisible by B, then a
stringsize condition is signalled. If the on-unit handing this
condition returns to the point of error, then length of the result is
extended by adding B - mod(L, B) zeros to the right end of the result
to enable correct display of the last digit in the result. Note that
the system default handler for stringsize silently returns to the point
of error, thus enabling a correct result to be displayed.
Examples:
To convert an octal output word from the ring_zero_dump command as a
binary bit string:
string [ring_zero_dump 71|3357 0 1]
400000000000
bit_string [ring_zero_dump 71|3357 0 1] -in o
"100000000000000000000000000000000000"b
This same result could be displayed for this input if a trailing
radix indicator string were given at the end of the first argument.
bit [ring_zero_dump 71|3357 0 1]o
"100000000000000000000000000000000000"b
Since the default INPUT_RADIX is octal and the default OUTPUT_RADIX is
binary, only the INPUT_STR need be given.
bit [ring_zero_dump 71|3357 0 1]
"100000000000000000000000000000000000"b
To express an octal bit string properly in hexadecimal, "0"b bits must
be added to the input bit string to fill out the final hex digit. This
is shown in the example below.
bit 051o
"000101001"b
bit 051o -length 12
"000101001000"b
bit 051o -length 12 -out b4
"148"b4
Extending the length of the result bit string would occur with the
default handling for the stringsize condition, as shown below.
bit 051 -out b4
"148"b4
https://s3.amazonaws.com/eswenson-multics/public/mcrs/MCR10162.pdf