Autor Beitrag
Tobias1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Do 19.05.05 10:24 
Welchen Wert gibt der Computer mir zurück bei and, or, xor-Verknüpfungen mit zwei Zahlen.
z.B x:=14 or 1 =>x=15
z.B x:=20 or 15=>x=31
Nach welchem Schema geht das?

_________________
Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 19.05.05 10:46 
Es ist ein binärer Vergleich der Zahlen.
Bei OR genügt es, wenn ein Bit gesetzt ist, um im Ergebnis gesetzt zu sein.
Be XOR darf nur eins der Bits gesetzt sein, um Ergebnis gesetzt zu sein.

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
14 =  1110
 1 =  0001
OR -> 1111 -> 15
XOR   1111 -> 15
20 =   10100
15 =    1111
OR  -> 11111 -> 31
XOR -> 11011 -> 27
Tobias1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Do 19.05.05 10:55 
Danke!
Jetzt versteh ich auch die xor-Verschlüsselung

_________________
Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Do 19.05.05 10:59 
n code, der dir ne tabelle mit zahlen und den jeweiligen binärwerten bei verschiedenen bit-operationen erzeugt

ausblenden volle Höhe 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:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
function mathop(z1,z2:dword;op:dword):dword;
const ops: array [0..4] of string = ('and', 'or', 'xor', 'shr', 'shl');
var i : integer;
label jmp1;
begin
//    for i := 0 to 4 do if ops[i] = lowercase(op) then goto jmp1;
//    jmp1:
      case op of
          0 : result := z1 and z2;
          1 : result := z1 or  z2;
          2 : result := z1 xor z2;
          3 : result := z1 shr z2;
          4 : result := z1 shl z2;
      end;
    //end;
end;

function dw2system(d,base:dword;strlen:byte):string;
// converts d in a system based on base
// like dw2system(255,2,8) = '11111111'
// or dw2system(255,16,2) = 'FF'
// by retnyg
const cypher = '0123456789ABCEDF';
var i : dword;
begin
   setlength(result,strlen);
   fillchar(pointer(result)^,strlen,48);
   while (d > 0) and (strlen > 0) do begin
     i := d mod base;
     result[strlen] := cypher[i+1];
     dec(d,i);
     dec(strlen);
     d:=d div base;
   end;
end;

function dectobin(z:dword):string;
var s: string;l:dword;
begin
 result := dw2system(z,2,8);
// result:= dectobase(z,16);
 exit;
 result:=dectobase(z,2); l:=length(result);
 while l < 8 do begin
   result := '0' + result;
   inc(l);
 end;
end;

function outstr(n:dword):string;
begin
   result :=dw2system(n,2,8);
   result:=inttostr(n)+':'+result;
end;

procedure TForm1.Button4Click(Sender: TObject);
const ca=';';
var i,j,z2 : integer;
append: boolean;
s:string;
f:textfile;

begin
  z2:=7;
  append := false;
  assignfile(f,'out.csv');
  rewrite(f);
  writeln(f,'number1;number2;AND;OR;XOR;SHR;SHL');
  for i := 0 to 255 do begin
    s := outstr(i) + ca + outstr(z2);
    for j := 0 to 4 do s := s + ca + outstr(mathop(i,z2,j));
    //if i = 31 then asm int 3 end;
    writeln(f,s);
//    if i = 1 then append := true;
//    writetotextfile('out.csv',s,append);
  end;
  closefile(f);
  sendmessage(handle,wm_close,0,0);
end;

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Do 19.05.05 11:20 
nur so zur info

and = beides muss eine 1 sein
or = eins muss eine 1 sein
xor = entweder das eine oder das andere muss eine 1 sein

ausblenden Quelltext
1:
2:
3:
4:
5:
x1  x2 and  or xor
0   0   0   0   0
0   1   0   1   1
1   0   0   1   1
1   1   1   1   0

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit