Autor Beitrag
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Di 20.05.08 19:10 
Hallo,

ist es auch möglich mit einem TFileStream Bits auszulesen? Meine Datei beinhaltet nämlich einen Wert der nur 5 Bits hat und mit einem Byte lese ich ja 8 aus :(

Gruß,
Hendi
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 20.05.08 19:12 
Du liest immer ganze Bytes aus, aber dann kannst du ja mit Bitoperationen den Teil des Wertes daraus auslesen, den du haben möchtest.

// EDIT:
www.delphipraxis.net...n+mit+bitmasken.html
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Di 20.05.08 19:36 
Und wenn ich jetzt eine 9 als Byte auslese wäre das 00001001, oder? Und die ersten 5 Bits wären 10010?

Ich erklär mal was ich gerade mache:
Ich helfe david-kurz mit seinem FLV Player. Wir haben eine Dokumentation von Adobe zu FLV gefunden, in der steht:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Field             Type  Comment
Signature         UI8   Signature byte always 'F' (0x46)
Signature         UI8   Signature byte always 'L' (0x4C)
Signature         UI8   Signature byte always 'V' (0x56)
Version           UI8   File version (for example, 0x01 for FLV version 1)

TypeFlagsReserved UB[5] Must be 0
TypeFlagsAudio    UB[1] Audio tags are present
TypeFlagsReserved UB[1] Must be 0
TypeFlagsVideo    UB[1] Video tags are present

Den ersten Absatz können wir auch auslesen, da alles normale Bytes sind, nur dann wirds seltsam -> der nächste Byte ist in 4 Teile aufgesplittet.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 20.05.08 20:01 
Die ersten Bits wären 00001, die Reihenfolge ist schon ganz normal. (Wobei es auch noch Big Endian und Little Endian gibt, damit könntest du auch noch zu tun bekommen, keine Ahnung ob das relevant wird :mrgreen:)

Herausbekommen tust du einzelne Bits durch Verundung mit einer Bitmaske und / oder Shiften (Schieben) der Bits. Or und Shr / Shl eben.

Beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
01001011
Du willst die ersten 5 Bits
--> 01001011 shr 3 --> Bits nach rechts um 3 verschieben --> 01001

Du willst das siebente Bit:
--> 01001011 shr 1 and 00000001 --> 0100101 and 00000001 --> 1
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Di 20.05.08 22:16 
user profile iconjaenicke hat folgendes geschrieben:
Die ersten Bits wären 00001, die Reihenfolge ist schon ganz normal. (Wobei es auch noch Big Endian und Little Endian gibt, damit könntest du auch noch zu tun bekommen, keine Ahnung ob das relevant wird :mrgreen:)

Nein, das interessiert erst > 1 Byte ;)

user profile iconHendi48 hat folgendes geschrieben:
ausblenden Quelltext
1:
2:
3:
4:
TypeFlagsReserved UB[5] Must be 0
TypeFlagsAudio    UB[1] Audio tags are present
TypeFlagsReserved UB[1] Must be 0
TypeFlagsVideo    UB[1] Video tags are present

Ganz einfach: das alles Zusammen sind... na? Genau, 8 Bit, also 1 Byte. Ein ganz normales Flag also...
ausblenden Delphi-Quelltext
1:
2:
3:
Stream.Read(TypeFlags,1);
Audio:= TypeFlags AND $4; // Hex(4) = Bin(0100)
Video:= TypeFlags AND $1; // Hex(4) = Bin(0100)

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Mi 21.05.08 13:42 
OK, danke für die Hilfe, jetzt hab ichs verstanden!