De Morgansche Gesetze
-
Hey Leute hab gerade nen Knoten im Kopf.
Ehm will nur sicher stellen das das stimmt was ich da zusammengefasst habe:
char u8 *byte; if (!(byte[0] >= 0x32 && byte[0] <= 0x34)) { ... }
Das gleiche wie das hier:
char u8 *byte; if (byte[0] != 0x32 || byte[0] != 0x33 || byte[0] != 0x34) { ... }
-
Hans2 schrieb:
Hey Leute hab gerade nen Knoten im Kopf.
Ehm will nur sicher stellen das das stimmt was ich da zusammengefasst habe:
char u8 *byte; if (!(byte[0] >= 0x32 && byte[0] <= 0x34)) { ... }
Das gleiche wie das hier:
char u8 *byte; if (byte[0] != 0x32 && byte[0] != 0x33 && byte[0] != 0x34) { //nicht || ! ... }
-
Aber ich dachte:
!(a && b) == !a || !b
!(a || b) == !a && !b
-
Ja, na und?
Hans2 schrieb:
char u8 *byte; if (byte[0] != 0x32 || byte[0] != 0x33 || byte[0] != 0x34) { ... }
Das liefert doch immer wahr, denn byte[0] kann ja nur einen Wert annehmen, und ist somit immer für mindestens zwei der Vergleichswerte ungleich. Und da die Vergleiche mit 'oder' verknüpft sind, muss der gesamte Ausdruck immer wahr ergeben.
-
Die Umkehrung von >= ist ja auch nicht ! =
-
char u8 *byte; if (!(byte[0] >= 0x32 && byte[0] <= 0x34)) { ... }
ist das gleiche wie (hier war wohl dein Fehler)
char u8 *byte; if (!(byte[0] == 0x32 || byte[0] == 0x33 || byte[0] == 0x34)) { ... }
und jetzt deMorgan
char u8 *byte; if (byte[0] != 0x32 && byte[0] && 0x33 && byte[0] != 0x34) { ... }
Oder
char u8 *byte; if (!(byte[0] >= 0x32 && byte[0] <= 0x34)) { ... }
ist
char u8 *byte; if (!(byte[0] >= 0x32) || !(byte[0] <= 0x34)) { ... }
ist
char u8 *byte; if (byte[0] < 0x32 || byte[0] > 0x34) { ... }