![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
|
|
#1
|
|||
|
|||
|
Доброго времени суток, как можно реализовать DecToBin калькулятор на delphi? в интернете искал, не нашел. Обьясню: есть 2 edit'та и кнопка допустим вводим число 37 в первый, и надо чтоб во 2 edit'е появлялся ответ
в 2 системе (10 0101), и на оборот. Заранее спасибо) Желательно код))) |
|
#2
|
||||
|
||||
|
В старой доброй RxLib есть модуль rxStrUtils.pas. В этом модуле среди кучи полезных функций есть вот такие:
Код:
function Dec2Numb(N: Longint; A, B: Byte): string;
{ Dec2Numb converts the given value to a string representation with the
base equal to B and with the minimum number of digits (A) specified. }
function Numb2Dec(S: string; B: Byte): Longint;
{ Numb2Dec converts the given B-based numeric string to the corresponding
integer value. }
function IntToBin(Value: Longint; Digits, Spaces: Integer): string;
{ IntToBin converts the given value to a binary string representation
with the minimum number of digits specified. }Код:
{ Пpеобpазует целое число N в число по основанию B,
дополняя слева нулями до длины A и вставляя пробелы
через каждые С символов (0 - не вставляет).}
function AdvancedDec2Numb(const N: Integer; const A, B, C: Byte): string;
var
i, Len: Integer;
S: string;
begin
Result:= '';
S:= Dec2Numb(N, A, B);
Len:= Length(S);
if C > 0
then begin
for i:= Len downto 1 do
begin
Result:= S[i] + Result;
if (Len - i + 1) mod C = 0
then Result:= ' ' + Result;
end;
Result:= Trim(Result);
end
else Result:= S;
end; |
|
#3
|
||||
|
||||
|
Код:
function DecToBin(Value: Integer): String;
var
i: Integer;
begin
Result:='';
for i:=0 to 31 do
begin
Result:=IntToStr(Value and 1)+Result;
Value:=Value shr 1;
end;
end; |