0Pricing
Cryptology Academy · Lesson

Bitwise Operations Refresher

AND, OR, XOR, NOT, and bit-shift operations explained visually.

Bitwise Operations Refresher is a free Cryptology Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Welcome

Bitwise operations work directly on binary representations of numbers. They are the fundamental operations inside every symmetric cipher, hash function, and MAC.

AND Operation

AND returns 1 only when BOTH bits are 1. 0101 AND 0011 = 0001 Use case: masking — extracting specific bits. mask = 0xFF; low_byte = value & mask

OR Operation

OR returns 1 when AT LEAST ONE bit is 1. 0101 OR 0011 = 0111 Use case: setting specific bits. flags = flags | 0x04 # set bit 2

XOR Operation

XOR returns 1 when bits are DIFFERENT. 0101 XOR 0011 = 0110 Key property: A XOR A = 0, A XOR 0 = A. XOR is self-inverse: (A XOR B) XOR B = A

NOT Operation

NOT flips every bit. NOT 0101 = 1010 (in 4-bit context) Python: ~5 == -6 (due to two's complement) For unsigned: ~x & 0xFF masks to 8 bits

Left Shift (<<)

Left shift moves all bits left by n positions, filling with zeros on the right. 0001 << 3 = 1000 (= 8) a << n is equivalent to a × 2^n Used in key expansion and mixing operations.

Right Shift (>>)

Right shift moves bits right, discarding the lowest bits. 1000 >> 2 = 0010 (= 2) a >> n is equivalent to a ÷ 2^n (floor) Used to extract nibbles: (byte >> 4) & 0x0F

Rotation (ROTL/ROTR)

Rotation wraps bits around instead of discarding them. ROTL32(x, n) = (x << n) | (x >> (32-n)) Used in SHA-256, AES MixColumns, and ChaCha20 quarter-round.

XOR Swap Trick

XOR allows swapping without a temp variable: a ^= b b ^= a a ^= b Now a and b are swapped. Used in some cipher implementations for efficiency.

Python Bitwise Examples

a = 0b10110011 b = 0b11001100 print(bin(a & b)) # 0b10000000 print(bin(a | b)) # 0b11111111 print(bin(a ^ b)) # 0b01111111 print(bin(~a & 0xFF)) # 0b01001100

Bit Counting

bin(n).count('1') counts set bits (Hamming weight). The Hamming distance between two words is the number of bits that differ — critical in error correction and diff analysis.

Quick Check

What is 0b1010 XOR 0b1100 in binary?

Recap

Bitwise operations mastered! Next we use XOR to build an encryption scheme and discover the perfect-secrecy of the one-time pad.

Frequently asked questions

Is the “Bitwise Operations Refresher” lesson free?

Yes — the full text of “Bitwise Operations Refresher” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.

What will I learn in “Bitwise Operations Refresher”?

AND, OR, XOR, NOT, and bit-shift operations explained visually. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cryptology Academy?

No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Bitwise Operations Refresher” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cryptology Academy lesson?

Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Bitwise Operations Refresher
  2. XOR Encryption & the One-Time Pad
  3. Why XOR Alone Is Not Secure
  4. XOR Inside AES & Stream Ciphers
← Back to Cryptology Academy