Скачиваний:
20
Добавлен:
06.02.2016
Размер:
924 б
Скачать
unit modul01;

interface function octbin(s: string):string;
function binoct(dva:string):string;
const S:array['0'..'7'] of String[3]=('000','001','010','011','100','101','110','111');
implementation

//из 8 в 2
function octbin (s: string):string;
var bin,k: string; j: integer;
begin
for j:=1 to length(s) do
begin
case s[j] of
'1': k:='001';
'2': k:='010';
'3': k:='011';
'4': k:='100';
'5': k:='101';
'6': k:='110';
'7': k:='111';
end;
bin:=bin+k;
end;
octbin:=bin;
end;

//из 2 в 8
function binoct(dva:string):string;
var i: Integer; c: Char; vos: String; st: String[3];
begin

while length(dva) mod 3 <> 0 do dva:='0'+dva;
vos:='';
for i:=1 to length(dva) div 3 do
begin
st:=Copy(dva,3*I-2,3);
for c:='0' to '7' do if st=S[c] then vos:=vos+c
end;
binoct:=vos;
end;

end.
Соседние файлы в папке 8 лаб. Модульное программирование