PROC convert_to_octal_bytes, convert_to_octal_byte, contb (
  input, i: string = $required
  result, r: var of string = $required
  status)

  crev blanks k=string v='            '
  crev hex_value k=(string,16)
  crev temp k=(string, 8)
  crev zeros k=string v='0000000000000000'

  hex_value = $strrep($integer($value(input)), 16)
  $value(result) = ''
  IF hex_value = '-1' THEN
    $value(result) = blanks
  ELSE
    IF $strlen(hex_value) < 16 THEN
      hex_value = $substr(zeros, 1, 16-$strlen(hex_value)) // hex_value
    IFEND
    FOR i = 0 TO 3 DO

" truncate hex to 3 characters preceded by a 0 to ensure proper form of hex num"
" leaving 12 bits for interpretation"
      temp = $strrep($integer('0'//$substr(hex_value, (4*i+2), 3)//'(16)'), 8)
      IF $strlen(temp) < 4 THEN
        $value(result) = $value(result) // $substr(blanks, 1, 4-$strlen(temp))..
               // temp
      ELSE "$strlen(temp) =  4 -- guaranteed by previous truncation above"
        $value(result) = $value(result) // temp
      IFEND
    FOREND
  IFEND
PROCEND convert_to_octal_bytes

