// PascalABC.NET
// количество знаков - произвольное!
function HexDigitToBin(Self: char): string; extensionmethod;
begin
var bd: array of string := ('0000', '0001', '0010', '0011',
'0100', '0101', '0110', '0111', '1000', '1001', '1010',
'1011', '1100', '1101', '1110', '1111');
var hd := '0123456789ABCDEF';
var i := Pos(Self.ToUpper, hd);
Result := if i > 0 then bd[i - 1] else '****'
end;
function Bin4ToOct(Self: string): char; extensionmethod;
begin
var od: array of string := ('000', '001', '010', '011',
'100', '101', '110', '111');
var i := od.FindIndex(p -> p = Self);
Result := if i < 0 then '*' else i.ToString.First
end;
function HexToOct(Self: string): string; extensionmethod;
begin
var t := '';
foreach var c in Self do
t += c.HexDigitToBin;
var L := t.Length;
t := '0' * ((3 - L mod 3) mod 3) + t;
L := t.Length;
var n := L div 3;
Result := '';
for var i := 0 to n - 1 do
Result += t[3 * i + 1: 3 * i + 4].Bin4ToOct;
end;
begin
var x16 := ReadString('Введите 16-ричное число:');
var x8 := x16.HexToOct;
x8.Print
end.