Autor Beitrag
Xabitire
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 114

Win Xp, Win Vista
D6 PE, D7 PE
BeitragVerfasst: Mi 11.04.07 20:20 
Hi Leute,

ich wollte mal fragen ob es möglich ist, den binären Code einer Datei, also die ganzen Einsen und Nullen, einer beliebigen Datei auszulesen und beispielsweise in einem Memo auszugeben. Und dann würde mich natürlich noch interessieren wie es geht!

Grüße Blackbird8690
rizla
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 417
Erhaltene Danke: 2

XP
FPC mit Lazarus
BeitragVerfasst: Mi 11.04.07 20:33 
Hi,
das ist ganz einfach:
datei einlesen in ein array oder byteweise, jedes byte umwandeln und ausgeben.
code folgt asap (umwandlung integer in 0 & 1)..

:r:

_________________
if you have what they want - they'll find a way to take it (bruce sterling)
WOW - 10 JAHRE Mitglied beim Delphi-Forum. Wie die Zeit vergeht, Freunde.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 11.04.07 21:45 
Machen wir's einfach mal so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
Var
    Lookup: Array[Byte] of String;
    X, Y: Integer;

    FS: TFileStream;
    S: String;
begin
    For X:= Low(Byte) to High(Byte) do
    Begin
        Lookup[X] := '';
        For Y := 7 downto 0 do
            Lookup[X] := Lookup[X] + IntToStr(Ord(X and (1 shl Y) <> 0));
    end;

    FS := TFileStream.Create({...});
    S := '';
    While FS.Position < FS.Size Do
    Begin
        FS.ReadBuffer(Y, 1);
        S := S + ' ' + Lookup[Y];
    end;
    S := Trim(S);
end;


//Edit: Source etwas sauberer gestaltet; hier lesen auch Anfänger mit *G*

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Xabitire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 114

Win Xp, Win Vista
D6 PE, D7 PE
BeitragVerfasst: Do 12.04.07 09:47 
Habs jetzt hinbekommen!!!

Sieht bei mir jetzt ungefähr so aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Button1Click(Sender: TObject);
var Stream: tfileStream;
    b: byte;
begin

  if opendialog1.Execute then Stream := Tfilestream.create(opendialog1.FileName, fmopenread);

  While Stream.Position < Stream.Size do
  begin
    Stream.ReadBuffer(B,SizeOf(B));
    memo1.lines.text:= memo1.Lines.Text + inttostr(b) + '-';
  end;

  stream.free;

end.


Allerdings brauch ich jetzt für 5 Kb anzeigen zu lassen schon zwei Minuten!

Als ich dann mal noch einen Prozessbalken eingebaut habe hab ich feststellen müssen, dass die ersten 20% sofort da waren, die Berechnung dann aber, desto näher es an die 100% ging um so langsamer ablief!

Weiß vielleicht jemand wie man das optimieren kann?
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 12.04.07 18:21 
Ja ;-) Nutze BeginUpdate und EndUpdate ... oder keine VCL als Zwischenspeicher ... Oder was denkst Du, warum ich nen reinen String in meiner Version nutze?

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.