⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myutils.pas

📁 安全芯加密狗 安全芯加密狗
💻 PAS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -