Перевод чисел в системы счисления
- function BinToInt(const Value: string): Integer;
- var
- i, strLen: Integer;
- begin
- Result := 0;
- strLen := Length(Value);
- for i := 1 to strLen do
- if Value[i] = '1' then
- Result := Result or (1 shl (strLen - i))
- else
- Result := Result and not (1 shl (strLen - i));
- end;
- function dec2hex(value: dword): string[8];
- const
- hexdigit = '0123456789ABCDEF';
- begin
- while value <> 0 do
- begin
- dec2hex := hexdigit[succ(value and $F)];
- value := value shr 4;
- end;
- if dec2hex = '' then dec2hex := '0';
- end;
- function HexToInt(s: string): Integer;
- var
- s: string;
- begin
- s := '$' + ThatHexString;
- result := StrToInt(a);
- end;
- const HEX: array['A'..'F'] of INTEGER = (10, 11, 12, 13, 14, 15);
- function HextToInt2(str: string;): Integer;
- var
- Int, i: integer;
- begin
- Int := 0;
- for i := 1 to Length(str) do
- if str[i] < 'A' then
- Int := Int * 16 + ORD(str[i]) - 48
- else
- Int := Int * 16 + HEX[str[i]];
- Result := Int;
- end.
Так, парочка показательных примеров...