Autor Beitrag
bbplayer
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Mi 16.03.05 17:41 
ich habe ein feld, dass aus bytes besteht und will diese in hexzeichen umwandeln!
Wie bekomme ich das am besten hin?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6386
Erhaltene Danke: 146

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 16.03.05 17:42 
IntToHex sollte die passende Funktion sein.
bbplayer Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Mi 16.03.05 17:45 
nee das funzt nicht!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6386
Erhaltene Danke: 146

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 16.03.05 17:49 
Der Hex Wert von 240 wird zum Beispiel so angezeigt:
ausblenden Delphi-Quelltext
1:
  ShowMessage(intToHex(240,0));					

Und beim nächsten mal eben dazu schreiben, was nicht funzt (Fehlermeldung?).
Grendel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 443

Gentoo Linux, MacOS X, Win 2000
D5 Ent, D7 Ent, Lazarus, Anjuta, MonoDevelop
BeitragVerfasst: Mi 16.03.05 18:20 
Guck mal nach BinToHex()

Bis neulich ...
himitsu
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 40



BeitragVerfasst: Mi 16.03.05 18:52 
BinToHex ust das Richtige, für mehrere Bytes ... mit IntToHex kann man ja nur Byte-/Word-weise umwandeln...

mathematisch gesehn:
Hex = 16 Werte, das sind ja bekanntlich 4 Bits
1 Byte, das sollte auch bekannt sein besteht aus 8 Bits
das bedeutet 2x Hex = 1 Byte...

Byte and $0F = der 1. Hex-Anteil
Byte and $F0 = der 2. Hex-Anteil

den 2. Anteil solle man entspechend verschieben, damit man damit rechnen kann
> (Ord(Char) and $F0) shr 4 > oder einfach nur Ord(Char) shr 4

Umwandlung geht am einfachsten über 'ne Tabelle, oder einen String
Const HexChars1: Array[0..15] of Char = ('0', '1' ... '9', 'A' ... 'F');
Const HexChars2 = '0123456789ABCDEF';

ein Byte/Char to Hex ist also

HexString := HexChars1[Byte and $0F] + HexChars1[Byte shr 4];
HexString := HexChars2[Byte and $0F + 1] + HexChars2[Byte shr 4 + 1];

in einer Schleife wird dann daraus

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Const HexChars: Array[0..15of Char = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');

Var X: Array of Byte;
  S: String;
  i: Interger;


S := '';
For i := 0 to High(X) do
  S := S + HexChars[Byte and $0F] + HexChars[Byte shr 4];

//oder in Kurz

SetLength(S, Length(X) * 2);  // * 2, da ja 2 Zeichen pro Byte
For i := 0 to High(X) do Begin
  S[i * 2] := HexChars[Byte and $0F];
  S[i * 2 + 1] := HexChars[Byte shr 4];
End;


PS: BinToHex mach es so ähnlich wie die kurze Variante (vermute ich mal)

_________________
warum einfach wenn's auch kompliziert geht
schreib wie du willst und halt dich an keine standards