Autor Beitrag
NeWsOfTzzz
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Di 26.10.04 12:26 
Also ich hab ein Byte, wie wandel ich das in ein Char um? Ich meine da könnte man noch theoretisch ne Routine schreiben, die das Byte einliest und ein Char ausspuckt, wäre aber viel Schreibarbeit.
Ok ich hab die nächsten 4 Bytes, wie wandel ich die in Integer um? Auch hier könnte ich theoretisch eine Routine schreiben die das ausrechnet.
Aber wäre das Leben denn nicht viel schöner, wenn Delphi diese Funktionen bereitstellt? Zumindestens Byte to Char wäre hilfreich ^^ Der Rest dürfte net so schwer sein..
Luzzifus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 200

Win2K
D6 Prof
BeitragVerfasst: Di 26.10.04 12:30 
man könnte ja ganz einfach CHR(x) nehmen um aus nem einzelnen byte nen char zu machen :p


Zuletzt bearbeitet von Luzzifus am Di 26.10.04 12:36, insgesamt 2-mal bearbeitet
NeWsOfTzzz Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Di 26.10.04 12:31 
1. byte<>shortint..
2. thx ich wollte doch nur nen funktionsnamen hören ^^
aber mit anderen typen gibt´s das net oder?
Luzzifus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 200

Win2K
D6 Prof
BeitragVerfasst: Di 26.10.04 12:35 
vom umfang her ists das gleiche, shortint ist mit vorzeichen (-128 .. +127) und byte ohne (0 .. 255).

für welche anderen typen hättst du's denn noch gerne? ^^
NeWsOfTzzz Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Di 26.10.04 12:36 
Jepp den Unterschied meinte ich ja.. Naja am besten für Integer.. aber noch besser wäre byte to char(=chr) und char to byte sowie byte[0..3] to integer und integer to byte[0..3]
Luzzifus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 200

Win2K
D6 Prof
BeitragVerfasst: Di 26.10.04 12:39 
CHR(x) -> wandelt byte in char um
ORD(x) -> wandelt char in byte um

und was du mit byte[0..3] to integer und integer to byte[0..3] meinst versteh ich nicht ganz. willst du die ascii-codes aneinandergehängt haben oder wat? :shock:
NeWsOfTzzz Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Di 26.10.04 12:41 
damit meinte ich 4 bytes in ein integer zu verwandeln (das ja bekanntlich aus 4 bytes besteht) und umgekehrt wäre auch praktisch..
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Di 26.10.04 12:44 
Integer <> Bytearray kannst du über einen Pointer machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  buf : array[0..3of Byte;
  i : ^Integer;
begin
  i:=Addr(buf[0]);
  ShowMessage(InttoStr(i^));


Gruß,
Jörg

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 26.10.04 12:46 
Vielleicht funktioniert das mit TypCasting:
IntegerVar := Integer(ArrayOf4ByteVar)

Habe ich aber so noch nicht ausprobiert. Und ob dabei was sinnvolles rauskommt ???
NeWsOfTzzz Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Di 26.10.04 12:46 
achso cool ^^ und von daher kann ich mir die bytes auch bestimmt mit der addresse von nem integer holen nur für jedes byte die addresse + 1 oder ?
ps: ich hab keine integer() funktion nur int() und die wandelt real in integer um..
Luzzifus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 200

Win2K
D6 Prof
BeitragVerfasst: Di 26.10.04 12:49 
das hier überträgt die vier bytes eines 4elementigen byte arrays auf ein 32bit integer. die einzelnen werte der bytes gehen logischerweise verloren (bis auf das letzte), aber die gesetzten bits werden 1:1 übertragen..
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function ByteArToInt(b: Array of Byte): Integer;
var
  i,x: Integer;
begin
  x:=0;
  if length(b) <> 4 then exit;
  for i:=0 to 3 do
  begin
    x:=x shl 8;
    x:=x+b[i];
  end;
  ByteArToInt:=x;
end;


Zuletzt bearbeitet von Luzzifus am Di 26.10.04 12:56, insgesamt 1-mal bearbeitet
NeWsOfTzzz Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Di 26.10.04 12:55 
hm mal gucken
irgendwie raff ich dat net lol
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Di 26.10.04 12:56 
Für den umgekehrten Weg poste ich mal noch eine andere äußerst coole Variante:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  b : array[0..3of Byte;
  i : Integer;
begin
  i:=$ABCDEF12;
  Move(i,b[0],4);

:cool:

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 26.10.04 12:57 
Beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
var
  s: String[3]; // Ist im Prinzip nichts anderes als ein array [0..3] of Byte;
  Z: Integer;
begin
  s:='ABC';
  z := Integer(s);
  ShowMessage(IntToStr(z));
end;

Getestet und funktioniert.
Luzzifus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 200

Win2K
D6 Prof
BeitragVerfasst: Di 26.10.04 13:00 
na super :shock: :D

aber meine lösung find ich auch hübsch :twisted:
NeWsOfTzzz Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Di 26.10.04 13:05 
integer() hab ich net :(
aber .chef´s byte to integer klappt PERFEKT °°
aber zum zweiten:
i:=$ABCDEF12;
Move(i,b[0],4);
WAs soll denn das erste sein?


Zuletzt bearbeitet von NeWsOfTzzz am Di 26.10.04 13:06, insgesamt 3-mal bearbeitet
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 26.10.04 13:06 
@Luzzifus:
Ich fürchte nur, dass NWOT damit überfordert ist. Erklär ihm doch mal was Bit-Verschiebungen sind.
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Di 26.10.04 13:08 
NeWsOfTzzz hat folgendes geschrieben:
WAs soll denn das erste sein?

Das ...
NeWsOfTzzz hat folgendes geschrieben:
i:=$ABCDEF12;

... ist lediglich ein Beispielwert gewesen. Ich dachte, dass sieht man. :?

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
NeWsOfTzzz Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Di 26.10.04 13:10 
Jo schon klar.. aber ich muss i doch vorher nichts zuweisen? oder doch?
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Di 26.10.04 13:13 
Theoretisch musst du nichts zuweisen. Das Bytearray bekommt dann eben genau den zufälligen Wert, der gerade in i rumlungert.

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!