myutils.pas

来自「安全芯加密狗 安全芯加密狗」· PAS 代码 · 共 56 行

PAS
56 行
字号
unit myUtils;

interface


function Str2Word(str : String): Integer;
function Str2Char(str: String) : Integer;

implementation

function GetCharHexValue(ch: Char) : Integer;
begin
    if ch in ['0'..'9'] then
        Result := Integer(Ord(ch) - Ord('0'))
    else
    begin
        ch := UpCase(ch);
        if ch in ['A'..'F'] then
            Result := Integer(Ord(ch) - Ord('A') + 10)
        else
            Result := -1;
    end;
end;

function Str2Char(str: String) : Integer;
var
    i1, i2:integer;
begin
    Result := -1;
    if( Length(str) = 2) then
    begin
        i1 := GetCharHexValue(str[1]);
        i2 := GetCharHexValue(str[2]);
        if( i1 <> -1) and (i2 <> -1) then
            Result := i1*16 + i2;
    end;
end;

function Str2Word(str : String): Integer;
var
    i1, i2 ,i3, i4: Integer;
begin
    Result := -1;
    if( Length(str) = 4) then
    begin
        i1 := GetCharHexValue(str[1]);
        i2 := GetCharHexValue(str[2]);
        i3 := GetCharHexValue(str[3]);
        i4 := GetCharHexValue(str[4]);
        if( i1 <> -1) and (i2 <> -1) and (i3 <> -1) and (i4 <> -1) then
            Result := i1*16*16*16 + i2*16*16 + i3*16 + i4;
    end;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?