Показать сообщение отдельно
  #5  
Старый 28.03.2008, 22:29
kobezzza kobezzza вне форума
Прохожий
 
Регистрация: 28.03.2008
Сообщения: 13
Репутация: 10
По умолчанию

Всё сделал))

Выложу код для перевода из 2-й в 10-ю и наоборот, мб кому пригодится)

из 10-й в 2-ю

Код:
procedure TForm1.DecToBinClick(Sender: TObject);
var
result:string;
dec:integer;
begin
dec:=StrToInt(BinDec.Text);
result:='';
While dec>0 do
begin
  if Odd(dec) then result:='1'+result
  else result:='0'+result;
  dec:=dec shr 1;
end;
if result='' then result:='0';
tr.Caption:=result;
end;

из 2-й в 10-ю
Код:
procedure TForm1.BinToDecClick(Sender: TObject);
var
i,result:integer;
bin:string;
begin
bin:=BinDec.Text;
result:=0;
for i:=1 to length(bin) do
begin
if (copy(BinDec.Text,i,1)<>IntToStr(1))
and (copy(BinDec.Text,i,1)<>IntToStr(0))
then
begin
ShowMessage('Ошибка');
Exit;
end;
if not (copy(BinDec.Text,i,1)<>IntToStr(1)) then
result:=result+(1 shl(length(bin)-i));
end;
tr.Caption:=IntToStr(result);
end;
Ответить с цитированием