Autor Beitrag
Killmag10
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Sa 13.11.04 15:48 
Hi

Wie kann ich am besten von 1 Bite alle 8 Bit herausfinden ?

das kann man doch bestimmt ausrechnen oder ?

also das muss dann dort rein

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
record = T8Bit
Bit1 :Boolean;
Bit2 :Boolean;
Bit3 :Boolean;
Bit4 :Boolean;
Bit5 :Boolean;
Bit6 :Boolean;
Bit7 :Boolean;
Bit8 :Boolean;
end;


mfg. Killmag10

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Sa 13.11.04 15:57 
Schreib mal alle Zahlen, bei denen je ein anderes Bit gesetzt ist hin:
ausblenden Quelltext
1:
2:
00000001 00000010 00000100...
       1        2        4...

Wenn Du jetzt eine beliebige Zahl per AND mit z.B. 4 verknüpfst:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var i: Integer;
{...}
i := 7;
if (i and 4 = 4) then
  bit2istgesetzt
else
  bit2istnichtgesetzt;

So kannst Du es bei Integern für alle 32 Bits machen.

Gruß,

raziel

_________________
JSXGraph
Alstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 827



BeitragVerfasst: Sa 13.11.04 16:00 
Hi raziel!

Könnte sein, dass ich mich irre, aber bei der "4" muss da nicht Bit3 und nicht Bit2 gesetzt sein?

Alstar
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Sa 13.11.04 16:07 
Ich fang bei 0 an zu zählen ;)

ausblenden Quelltext
1:
2:
b7b6b5b4b3b2b1b0
 0 0 0 0 0 1 0 0 = 4


Hättest Du gesagt "3. Bit" würde ich Dir zustimmen, wäre aber trotzdem nicht falsch gelegen.

_________________
JSXGraph
Alstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 827



BeitragVerfasst: Sa 13.11.04 16:10 
[quote=raziel]
Ich fang bei 0 an zu zählen :wink:
[/quote]

Wie jetzt "0"? So ein Schwachsinn ... Da sind 8 Ziffern, also 8 Bit ...
Fängst du, wenn du Geld zählst, auch bei "0" an? :rofl:

Alstar
Nightmare_82
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 260



BeitragVerfasst: Sa 13.11.04 16:11 
mit einer Schleife von 0 bis 7 kannst du per and-vergleich abfragen, welche bits gesetzt sind.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
x : Byte;
i : Integer;
begin
x:= 127;
for i:= 0 to 7 do
begin
 if (x and (1 shl i) > 0) then
 begin
   // Bit i ist gesetzt
 end;
end;

Diese Schleife macht einen And-Vergleich mit 1,2,4,8... wie raziel es oben erklärt hat.
Stefan-W
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 475

Win 7 SP1
D2005 PE
BeitragVerfasst: Sa 13.11.04 16:16 
Es stimmt es sind 8 Zahlen, aber in der Digitaltechnik geht es mit 0 los! Also:
Bit7, Bit6, Bit5, Bit4, Bit3, Bit2, Bit1, Bit0
0 , 0 , 0 , 0 , 0 , 1 , 0 , 0
Basti
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 345

Windows Vista
D2005 Pers, D7 Pers
BeitragVerfasst: Sa 13.11.04 16:17 
Mal ganz nebenbei: Es bietet sich an ein Array dafür zu nehmen:
ausblenden Delphi-Quelltext
1:
2:
3:
T8Bit = record
  Bit: Array[1..8] of Boolean;
end;

_________________
Der Computer ist die logische Weiterentwicklung des Menschen: Intelligenz ohne Moral.
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Sa 13.11.04 16:17 
Alstar hat folgendes geschrieben:
Wie jetzt "0"? So ein Schwachsinn ... Da sind 8 Ziffern, also 8 Bit ...
Fängst du, wenn du Geld zählst, auch bei "0" an? :rofl:

Man mag mich engstirnig nennen, aber ich kann beim besten Willen nichts Lustiges erkennen...
Wenn ich ein Bit habe, kann ich das doch "Bit 0" nennen, oder etwa nicht? Ich könnts auch "Apfel", "Bockwurst" oder "Alstar" nennen, aber nein, ich nenns (wie viele andere) "Bit 0" oder "b0".

Wenn ich einen 5-Euro Schein besitze gilt genau das gleiche. Ich hab 5 (in Worten: fünf) Euro, aber kann den nennen wie ich will (von mir aus auch "0").

raziel

_________________
JSXGraph
Killmag10 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Sa 13.11.04 16:35 
ehm ja aber. ihrgentwie is das sinlos weil ich dann klei prüfen kann ob Bite 4 is

aber ich will das ich auch 10011011 auslesen kann


gibts da nicht ne umrechnungszahl?


weil ich will eine kompriemierung schreiben und da muss ich jedes einzellne bit setzen können

mfg Killmag10

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Sa 13.11.04 16:41 
Und exakt das machst Du so, wie oben beschrieben.
AND heißt UND:
ausblenden Quelltext
1:
2:
3:
4:
     10010111 = 151
and  00000100 = 4
-------------
     00000100 = 4

=> Bit 2 (bzw. das 3. Bit von links) ist gesetzt.

_________________
JSXGraph
Killmag10 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Sa 13.11.04 16:59 
raziel hat folgendes geschrieben:
Und exakt das machst Du so, wie oben beschrieben.
AND heißt UND:
ausblenden Quelltext
1:
2:
3:
4:
     10010111 = 151
and  00000100 = 4
-------------
     00000100 = 4

=> Bit 2 (bzw. das 3. Bit von links) ist gesetzt.


aso gut ich probiers mal aus.

schonmal danke

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 13.11.04 17:41 
Hallo!

Raziels Bezeichnung ist IMHO sehr viel besser, als wenn man anfinge, bei 1 zu zählen. Denn Eine Zahl setzt sich ja aus 2^0, 2^1, etc. zusammen. Die Exponenten beginnen bei 0, nicht bei 1!

MfG
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Sa 13.11.04 17:43 
Aber ...

Killmag10 hat folgendes geschrieben:
Wie kann ich am besten von 1 Bite alle 8 Bit herausfinden ?


Das geht nicht. Ein Bit hat den Zustand 1 oder 0. Man kann aber aus einem Byte alle 8 Bit herausfinden.

_________________
Gruß
Martin
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Sa 13.11.04 17:54 
Und noch was ...

Stefan-W hat folgendes geschrieben:
Es stimmt es sind 8 Zahlen, aber in der Digitaltechnik geht es mit 0 los! Also:
Bit7, Bit6, Bit5, Bit4, Bit3, Bit2, Bit1, Bit0
0 , 0 , 0 , 0 , 0 , 1 , 0 , 0


Es stimmt schon, daß man es Bit0 nennen kann. Jeder kann es für sich schreiben wie er es lustig findet. Und

2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
...

Aber man spricht beim Bit0 dennoch vom ersten Bit. Das Bit1 hier wäre dann das zweite Bit. Und schon sind alle verwirt.

Das hört sich jetzt kleinlich an, aber wenn einer jetzt von 3. Bit spricht, dann muß man wissen um welches Bit es sich handelt. Also das 3. Bit ist jetzt das dritte von rechts. Wenn man das erste meint, dann spricht nicht von dem Nullten Bit. Es ist das erste Bit. Wie man es berechnet ist eine ganz andere Sache.

_________________
Gruß
Martin
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 13.11.04 18:13 
MartinPb hat folgendes geschrieben:
Das hört sich jetzt kleinlich an, aber wenn einer jetzt von 3. Bit spricht, dann muß man wissen um welches Bit es sich handelt. Also das 3. Bit ist jetzt das dritte von rechts. Wenn man das erste meint, dann spricht nicht von dem Nullten Bit. Es ist das erste Bit. Wie man es berechnet ist eine ganz andere Sache.
Also ich finde es ganz normal, von einem nullten Element oder Bit zu sprechen. Das erste Mal, wenn man es hört, ist es etwas komisch, aber inzwischen habe ich mich dran gewöhnt. Beide Sprechweisen sind gleichberechtigt, man kommt also nicht umhin zu sagen, welche man meint.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Sa 13.11.04 19:26 
Heist das, die Sache soll so funktionieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var   
  x : Byte;   
  i : Integer;
  Bit: Array[0..7] of integer;   
begin   
x:= 127;   
for i:= 0 to 7 do   
begin   
 if (x and (1 shl i) > 0) then      
 Bit[i]=1 else Bit[i]=0;
 end;   
end;

Also wenn ich z.B. 4 nehme, was ja 00000100 ist, dann ist nur Bit[2]=1, der rest ist 0?

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Sa 13.11.04 19:31 
Exakt ;)
And heißt ungefähr: "Setze alle Bits in der Ausgabe, wo in Eingabe 1 und in Eingabe 2 die jeweiligen Bits gesetzt sind".

_________________
JSXGraph
Killmag10 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 297

Suse Linux / DOS / Windows All In One ;)
D4 / D2005
BeitragVerfasst: Sa 13.11.04 21:50 
mit den auslesen das geht ganz gut aber wie geht das jetzt andersrum ?

weil wenn ich sage:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.SetByte(Bit: Array[1..8] of Boolean);
var
byte1 :byte;
begin

byte1:=Byte(Bit[8] and Bit[7] and Bit[6] and Bit[5] and Bit[4] and Bit[3] and Bit[2] and Bit[1]);

Result:=byte1;

end;


geht das voll in die hose.

_________________
Mega-inkompetente Computer-ruinierende Organisation spioniert ohne funktionierende Technik
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Sa 13.11.04 22:41 
Also erstmal: Klasse signatur *fg*
dann folgendes: and ist ein operator, der so nicht funktioniert. (glaube ich) ich würde empfehlen, aus dem array of boolean einen array of char oder string zu machen, und dann einfach in deiner setbyte funktion die ands mit + zu ersetzen. mein tipp also:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TForm1.SetByte(Bit: Array[1..8] of String);   
var   
Byte1 : String;   
begin   
byte1:=Byte(Bit[8] + Bit[7] + Bit[6] + Bit[5] + Bit[4] + Bit[3] + Bit[2] + Bit[1]);   
Result:=byte1;   
end;

procedure TForm1.GetBytes(x:Byte);
var       
  i : Integer;   
  Bit: Array[0..7] of String;       
begin       
x:= 127;       
for i:= 0 to 7 do       
begin       
 if (x and (1 shl i) > 0) then           
 Bit[i]='1' else Bit[i]='0';   
 end;       
end;


Nicht getestet, sollte aber klappen...

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.