От: | Hacker_Delphi | ||
Дата: | 02.01.03 11:09 | ||
Оценка: |
function IntToBin(AInt: int64): string;
begin
result := '';
while AInt > 0 do
begin
result := chr(ord('0') + (AInt and 1)) + result;
AInt := AInt shr 1;
end;
end;
function BinToInt(AStr: string): int64;
var
CurrPos: integer;
begin
result := 0;
if Length(AStr) > 64 then
raise EOverflow.Create('Integer value can have at maximum 63 bit!');
CurrPos := 1;
while Length(AStr) >= CurrPos do
begin
result := result shl 1;
case AStr[CurrPos] of
'0', '1':
result := result + ord(AStr[CurrPos]) - ord('0');
else
raise EConvertError.CreateFmt('Not a valid binary value: %s',
[AStr]);
end;
inc(CurrPos);
end;
end;
Необходимо подключить модуль SysUtils.