![]() |
AW: For-loop from C to Delphi
Easy to forget, since Union seemed to use a zero base on Strings, which can lead to quite some confusion - I know that first hand, since I regularly forget it myself. But you're right of course :)
|
AW: For-loop from C to Delphi
Yes this was for PChar (see StrCopy). But the principle was to show the StrToInt() and Ord() function's results.
|
AW: For-loop from C to Delphi
I tried to translate the two posted functions:
Delphi-Quellcode:
Untested, use at your own risk.
function ctoi(source: char): integer;
begin if (source >= '0') and (source <= '9') then Result := Ord(source) - Ord('0') else Result := Ord(source) - Ord('A') + 10; end; function itoc(source: integer): char; begin if (source >= 0) and (source <= 9) then Result := Chr(Ord('0') + source) else Result := Chr(Ord('A') + source - 10); end; |
AW: For-loop from C to Delphi
Oder kürzer Or shorter:
Delphi-Quellcode:
function ctoi(source: char): integer;
begin result := StrToInt('$'+source); end; function itoc(source: integer): char; begin c := Format('%x', [source])[1]; end; |
AW: For-loop from C to Delphi
And what about ctoi('Z')?
|
AW: For-loop from C to Delphi
Ok, my solution works only for hex :(
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:10 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz