Autor |
Beitrag |
.#R4id
      
Beiträge: 90
Windows XP Prof.
CodeGear Delphi 2007
|
Verfasst: So 02.12.07 14:10
Hat jemand die Funktionen StrToHex und/oder HexToStr
Wenn ja, bitte Posten.
Danke!
|
|
Gausi
      
Beiträge: 8548
Erhaltene Danke: 477
Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
|
Verfasst: So 02.12.07 14:15
Sicher, dass du die willst, und nicht lieber HexToInt / IntToHex, die bei Delphi dabei sind?
_________________ We are, we were and will not be.
|
|
Marc.
      
Beiträge: 1876
Erhaltene Danke: 129
Win 8.1, Xubuntu 15.10
|
Verfasst: So 02.12.07 14:15
Geht wohl um das Weihnachtsgewinnspiel.
HexToStr brauchst du beispielsweiße gar nicht, denn Hex ist bereits ein String.
Grüße
Marc
|
|
.#R4id 
      
Beiträge: 90
Windows XP Prof.
CodeGear Delphi 2007
|
Verfasst: So 02.12.07 16:49
|
|
Gausi
      
Beiträge: 8548
Erhaltene Danke: 477
Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
|
Verfasst: So 02.12.07 16:52
Dann frage ich mal so: Was ist denn "Hex"?
_________________ We are, we were and will not be.
|
|
.#R4id 
      
Beiträge: 90
Windows XP Prof.
CodeGear Delphi 2007
|
Verfasst: So 02.12.07 17:04
Ich weiß zwar nicht warum du jetzt diese Frage stellst, aber Hexadezimalsystem
|
|
Gausi
      
Beiträge: 8548
Erhaltene Danke: 477
Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
|
Verfasst: So 02.12.07 17:12
Das Hexadezimalsystem ist mir bekannt. Ich frage, was du dir darunter vorstellst, bzw. wie du die Unterschiede zwischen Hex, Int und String siehst.
Das z.B.: 'FFE098' ist eine String, der im Hexadezimalsystem einer Zahl entspricht. Da liegen dann irgendwo im Speicher 6 Bytes rum, plus 8 Byte Längenangabe und Referenzzähler. Mit HexToInt macht man daraus eine Zahl. Im Speicher liegen dann irgendwo vier Bytes, die man so darstellen kann: 00 FF E0 98. Mit IntToHex bekommt man wieder den String 'FFE098'.
Was also soll ein HexToString oder StringToHex machen?
|
|
.#R4id 
      
Beiträge: 90
Windows XP Prof.
CodeGear Delphi 2007
|
Verfasst: So 02.12.07 17:18
Nur mal so am rande, HexToInt gibt es bei mir garnicht...?!
|
|
Gausi
      
Beiträge: 8548
Erhaltene Danke: 477
Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
|
Verfasst: So 02.12.07 17:22
Liegt vielleicht daran, dass das StrToInt auch schon kann, wenn der Hexadezimaldarstellung der Zahl ein $ voransteht, wie es bei Delphi üblich ist. Aber IntToHex gibts auf jeden Fall.
_________________ We are, we were and will not be.
|
|
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: So 02.12.07 17:28
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36:
| function HexToNib(Hex: Char): Byte; begin if (Hex >= 'a') and (Hex <= 'z') then Hex := Chr(Ord(Hex) - Ord('a') + Ord('A')); if (Hex >= '0') and (Hex <= '9') then Result := Ord(Hex) - Ord('0') else if (Hex >= 'A') and (Hex <= 'F') then Result := 10 + Ord(Hex) - Ord('A') else raise Exception.Create('HexToNib: Invalid hex character'); end;
function NibToHex(Nib: Byte): Char; begin if (nib<10) then Result := Chr(nib + Ord('0')) else if (nib < 16) then Result := Chr(nib + 55) else raise Exception.Create('NibToHex: Nibble out of range'); end;
function HexToStr(S: string): string; var i: Integer; b: Byte; begin Result := ''; i := 1; while i < Length(S) do begin b := (HexToNib(S[i]) shl 4) or HexToNib(S[i + 1]); Inc(i, 2); Result := Result + Chr(b); end; end;
function StrToHex(S: string): string; var i: Integer; begin Result := ''; for i := 1 to Length(S) do Result := Result + NibToHex(Byte(S[i]) shr 4) + NibToHex(Byte(S[i]) and $F); end; |
|
|
.#R4id 
      
Beiträge: 90
Windows XP Prof.
CodeGear Delphi 2007
|
Verfasst: So 02.12.07 18:04
Danke, hathor das du so gnedig warst.
Gausi, auch an dich Danke! ^^
|
|