نمایش نتایج 1 تا 4 از 4

نام تاپیک: تبدیل رشته حاوی عدد Hex به Integer

  1. #1

    Question تبدیل رشته حاوی عدد Hex به Integer

    چه جوری یه عدد Hex را به Integer تبدیل کنم
    آیا تابع مستقیم برای این کار وجود داره یا باید خودم بسازمش

  2. #2
    کاربر دائمی آواتار sasan_vm
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    زاهدان
    پست
    494

    نقل قول: تبدیل رشته حاوی عدد Hex به Integer


    HexStr : string;
    Num : int;
    HexStr := '$AFBF12';
    Num := StrToInt(HexStr);

  3. #3
    کاربر دائمی آواتار K.Mohammadreza
    تاریخ عضویت
    فروردین 1388
    محل زندگی
    کرمان
    پست
    285

    نقل قول: تبدیل رشته حاوی عدد Hex به Integer

    با سلام توابع زير مشکلتو حل مي کنن

    function HexToInt(Str: string): Integer;
    var
    intC: Integer;
    intL: Integer;
    chrC: Char;
    begin
    Str := UpperCase(Str);
    Result := 0;
    intL := Length(Str);
    for intC := intL downto 1 do
    begin
    chrC := Str[intC];
    if(chrC <= 'F')and(chrC >= 'A')then
    Result := Result + (Ord(chrC) - 55)shl((intL - intC) shl 2)
    else
    if(chrC <= '9')and(chrC > '0')then
    Result := Result + (Ord(chrC) - 48)shl((intL - intC) shl 2);
    end;
    end;
    function BinToInt(Str: string): Integer;
    var
    intC: Integer;
    intL: Integer;
    chrC: Char;
    begin
    Result := 0;
    intL := Length(Str);
    for intC := intL downto 1 do
    begin
    chrC := Str[intC];
    if chrC = '1' then
    Result := Result + 1 shl (intL - intC);
    end;
    end;
    function OctalToInt(Str: string): Integer;
    var
    intC: Integer;
    intL: Integer;
    chrC: Char;
    begin
    Result := 0;
    intL := Length(Str);
    for intC := intL downto 1 do
    begin
    chrC := Str[intC];
    if(chrC >= '0')and(chrC <= '7')then
    Result := Result + (Ord(chrC) - 48)shl((intL - intC) * 3);
    end;
    end;
    function AsciiToInt(Str: string): integer;
    var
    intC: Integer;
    intL: Integer;
    chrC: Char;
    begin
    Result := 0;
    intL := Length(Str);
    for intC := intL downto 1 do
    begin
    chrC := Str[intC];
    Result := Result + Ord(chrC)shl((intL - intC) shl 8);
    end;
    end;
    function IntToBin(intI: Integer): string;
    var
    intD: Integer;
    bytV: Byte;
    bolN: Boolean;
    begin
    bolN := (intI < 0);
    intI := ABS(intI);
    intD := 0;
    Result := '';
    repeat
    bytV := (intI shr intD) and 1;
    Result := Chr(bytV + 48) + Result;
    Inc(intD);
    until (intI < (1 shl intD));
    if bolN then
    Result := '-' + Result;
    end;
    function IntToOctal(intI: Integer): string;
    var
    intD: Integer;
    bytV: Byte;
    bolN: Boolean;
    begin
    bolN := (intI < 0);
    intI := ABS(intI);
    intD := 0;
    Result := '';
    repeat
    bytV := (intI shr intD) and 7;
    Result := Chr(bytV + 48) + Result;
    Inc(intD,3);
    until (intI < (1 shl intD));
    if bolN then
    Result := '-' + Result;
    end;
    function IntToHex(intI: Integer): string;
    var
    intD: Integer;
    bytV: Byte;
    bolN: Boolean;
    begin
    bolN := (intI < 0);
    intI := ABS(intI);
    intD := 0;
    Result := '';
    repeat
    bytV := (intI shr intD) and $F;
    if bytV > 9 then
    Result := Chr(bytV + 55) + Result
    else
    Result := Chr(bytV + 48) + Result;
    Inc(intD,4);
    until (intI < (1 shl intD));
    if bolN then
    Result := '-' + Result;
    end;
    function IntToAscii(intI: Integer): string;
    var
    intD: Integer;
    bytV: Byte;
    bolN: Boolean;
    begin
    bolN := (intI < 0);
    intI := ABS(intI);
    intD := 0;
    Result := '';
    repeat
    bytV := (intI shr intD) and $ff;
    Result := Chr(bytV) + Result;
    Inc(intD, 8);
    until (intI < (1 shl intD));
    if bolN then
    Result := '-' + Result;
    end;

  4. #4

    نقل قول: تبدیل رشته حاوی عدد Hex به Integer

    نقل قول نوشته شده توسط sasan_vm مشاهده تاپیک

    HexStr : string;
    Num : int;
    HexStr := '$AFBF12';
    Num := StrToInt(HexStr);
    تا اونجا که من میدونم نوع داده ای به نام Int در دلفی اعتبار ندارد و باید از Integer به جای آن استفاده کرد .

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •