Autor Beitrag
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Di 01.02.11 00:29 
Hi,

ich habe hier diese zeile code in der generierung eines MD5 Hashes:

ausblenden Quelltext
1:
x & y | ~x & z					


Der funktioniert wunderbar, allerdings habe ich beim compilieren immer ne Warning:

ausblenden Quelltext
1:
warning: suggest parentheses around arithmetic in operand of '|'					


Die würd ich gern wegbekommen und eben klammern setzen. Nur.. wie? :)
Also wie ist ohne klammern die ausführ-reihenfolge?

Klar könnte ich die warning einfach ignorieren oder abschalten.. aber na ja..

Danke,
Aya

_________________
Aya
I aim for my endless dreams and I know they will come true!
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: Di 01.02.11 00:43 
Schauen wir doch einfach mal in's RFC:

ausblenden Quelltext
1:
2:
3:
4:
F(X,Y,Z) = XY v not(X) Z
G(X,Y,Z) = XZ v Y not(Z)
H(X,Y,Z) = X xor Y xor Z
I(X,Y,Z) = Y xor (X v not(Z))


Zu finden unter 3.4. Auch den Absatz unter dem Block lesen. HTH.

_________________
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.
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 01.02.11 09:27 
Schauen wir mal in die Wikipedia ;)

~ vor & vor |, sollte also

ausblenden Quelltext
1:
(x & y) | ((~x) & z)					

sein, wenn mans völlig übertreibt. Dabei ist natürlich mindestens die an der Negation überflüssig.

Warum sich der Compiler da meldet ist mir aber nicht wirklich klar... ist doch wirklich eindeutig?

EDIT: binäres und logisches NOT verwechselt.

_________________
"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."


Zuletzt bearbeitet von Martok am Di 01.02.11 16:22, insgesamt 1-mal bearbeitet
Greenberet
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 339
Erhaltene Danke: 20

Win 10
C# (VS 2012), C++ (VS 2012/GCC), PAWN(Notepad++), Java(NetBeans)
BeitragVerfasst: Di 01.02.11 09:57 
user profile iconMartok hat folgendes geschrieben Zum zitierten Posting springen:
Schauen wir mal in die Wikipedia ;)

! vor & vor |, sollte also

ausblenden Quelltext
1:
(x & y) | ((~x) & z)					

sein, wenn mans völlig übertreibt. Dabei ist natürlich mindestens die an der Negation überflüssig.

Warum sich der Compiler da meldet ist mir aber nicht wirklich klar... ist doch wirklich eindeutig?


Der Compiler meldet sich weil es dadurch lesbarer wird.
Sicher ist den meisten Klar wie die Berechnung funktioniert. Wenn man allerdings längere Ausdrücke bzw mehrere hat und irgendwo ein kleiner Fehler ist, dann tut man sich mit Klammern um einiges leichter =)
Aya Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Di 01.02.11 20:48 
user profile iconMartok hat folgendes geschrieben Zum zitierten Posting springen:
Schauen wir mal in die Wikipedia ;)

Danke :)

seh ich das dann richtig das wenn ich dashier klammern möchte:

ausblenden Quelltext
1:
0x80000000 + (i - 32) << 23					


es so richtig ist:

ausblenden Quelltext
1:
(0x80000000 + (i - 32)) << 23					


Wenn ich die tabelle bei Wikipedia richtig deute kommt + vor << richtig?

Danke,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
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: Di 01.02.11 22:10 
Richtig.

_________________
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.