0Pricing
Zig Academy · Lektion

Bitweise Operatoren

AND, OR, XOR, NOT und Verschiebungen.

Bitweise Operatoren ist eine kostenlose Zig Academy-Lektion auf CoddyKit. Dies ist Lektion 3 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Zig Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Zig Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Down to the Bits

Every integer is really a row of bits. Bitwise operators let you work on those individual ones and zeros directly, with no rounding or math in between.

Bitwise AND

The & operator keeps a bit only where both inputs have a 1. It is the classic tool for masking off the bits you do not want.

const masked = value & 0x0F;

Bitwise OR

The | operator sets a bit where either input has a 1. Use it to turn specific flags on without disturbing the rest.

const withFlag = value | 0b0010;

Bitwise XOR

The ^ operator sets a bit only where the inputs differ. XOR is handy for toggling a flag or comparing two patterns.

const toggled = value ^ 0b0001;

Bitwise NOT

The unary ~ operator flips every bit at once: each 1 becomes 0 and each 0 becomes 1. It builds the complement of a value.

const inverted = ~flags;

Shifting Left

The << operator slides bits toward the high end, filling in zeros. Each shift left by one doubles an unsigned value.

const doubled = x << 1;

Shifting Right

The >> operator moves bits toward the low end. For an unsigned integer, each right shift by one halves the value.

const halved = x >> 1;

Masking Reads Bits

Combine AND with a mask to test whether a bit is set. If value & mask is nonzero, that flag is on; if zero, it is off.

const isSet = (value & mask) != 0;

Setting and Clearing

OR a mask to set bits, and AND with an inverted mask to clear them. Together they give you precise control over each flag.

const cleared = value & ~mask;

Shift Amounts Are Checked

Zig will not let you shift by more than the type holds. A shift amount out of range is a defined error, not silent garbage.

Why Bits Matter

Bit operations power flags, permissions, hardware registers, and compact data. They let you store many true-or-false answers in a single number.

Quick Check

You want a bit set only when the two inputs differ. Which operator?

Recap: Master of Bits

You now use &, |, ^, ~, plus the shifts << and >>, to read, set, clear, and move bits with full precision. ⚙️

Häufig gestellte Fragen

Ist die Lektion „Bitweise Operatoren“ kostenlos?

Ja — der vollständige Text von „Bitweise Operatoren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Zig Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Zig Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Bitweise Operatoren“?

AND, OR, XOR, NOT und Verschiebungen. Du übst Zig Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Zig Academy zu starten?

Keine Vorkenntnisse erforderlich. Zig Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 3 von 4.

Wie lange dauert die Lektion „Bitweise Operatoren“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Zig Academy-Lektion Code schreiben und ausführen?

Ja. Jede Zig Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Arithmetische und Vergleichsoperatoren
  2. Überlauf: + vs +% vs +|
  3. Bitweise Operatoren
  4. Boolesche Logik und Kurzschlussauswertung
← Zurück zu Zig Academy