function BinToHex(mBin: string): string;
var
I, J, L: Integer;
S: string;
begin
S := '';
L := Length(mBin);
if L mod 4 <> 0 then
for I := 1 to 4 - (L mod 4) do
mBin := '0' + mBin;
for I := Length(mBin) downto 1 do begin
S := mBin[I] + S;
if Length(S) = 4 then begin
for J := 0 to 15 do
if S = cBinStrings[J] then begin
S := IntToHex(J, 1);
Break;
end;
if Length(S) > 1 then
Result := '0' + Result
else Result := S + Result;
S := '';
end ;
end;
end; { BinToHex }
function HexToBin(mHex: string): string;
var
I: Integer;
begin
Result := '';
for I := 1 to Length(mHex) do
Result := Result + cBinStrings[StrToIntDef('$' + mHex[I], 0)];
while Pos('0', Result) = 1 do Delete(Result, 1, 1);
end; { HexToBin }
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := HexToBin(Edit2.Text);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Edit2.Text := BinToHex(Edit1.Text);
end;
function IntToDigit(mNumber: Integer; mScale: Byte; mLength: Integer = 0): string;
var
I, J: Integer;
begin
Result := '';
I := mNumber;
while (I >= mScale) and (mScale > 1) do begin
J := I mod mScale;
I := I div mScale;
Result := cScaleChar[J + 1] + Result;
end;
Result := cScaleChar[I + 1] + Result;
if mLength > 0 then
for I := 1 to mLength - Length(Result) do
Result := '0' + Result;
end; { IntToDigit }
function DigitToInt(mDigit: string; mScale: Byte): Integer;
var
I: Byte;
L: Integer;
begin
Result := 0;
L := Length(mDigit);
for I := 1 to L do
Result := Result + (Pos(mDigit[L - I + 1], cScaleChar) - 1) *
Trunc(IntPower(mScale, I - 1));
end; { DigitToInt }