Bitwise and Shift Instructions
Master bit manipulation in x86: AND, OR, XOR, NOT, and the shift and rotate instructions used for masking, flag toggling, and fast multiplication.
Bitwise and Shift Instructions is a free Assembly Language & x86 Low-Level Systems Programming lesson on CoddyKit — lesson 4 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 Assembly Language & x86 Low-Level Systems Programming learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Bit Operations?
Low-level code constantly manipulates individual bits: setting flags, packing fields, masking, and fast math. x86 provides dedicated bitwise and shift instructions.
AND for Masking
AND keeps only the bits set in both operands, the standard way to mask out unwanted bits.
and eax, 0x0F ; keep low nibbleOR for Setting Bits
OR forces specific bits to 1 while leaving others unchanged.
or eax, 0x80 ; set bit 7XOR for Toggling
XOR flips bits where the mask is 1. A famous idiom zeroes a register quickly:
xor eax, eax ; eax = 0NOT for Inversion
NOT flips every bit (ones complement).
not eaxLogical Shift Left (SHL)
SHL shifts bits left, filling with zeros. Each shift left multiplies an unsigned value by two.
shl eax, 1 ; eax = eax * 2Logical Shift Right (SHR)
SHR shifts right with zero fill, dividing an unsigned value by powers of two.
shr eax, 2 ; unsigned eax / 4Arithmetic Shift (SAR)
SAR shifts right but preserves the sign bit, so it divides signed values correctly.
sar eax, 1 ; signed eax / 2Rotate Instructions
ROL and ROR rotate bits around, wrapping the bit that falls off back in on the other side, used in hashing and crypto.
rol eax, 4Bit Test Instructions
BT copies a chosen bit into CF so you can test it, while BTS/BTR test and set/reset it.
bt eax, 3 ; CF = bit 3 of eaxCommon Idioms
Handy patterns:
xor reg, regto zeroshl/shrfor power-of-two mathand reg, maskto extract fields
Quick Check
Test your understanding of bit operations.
Recap
You learned bitwise and shift instructions:
- AND mask, OR set, XOR toggle, NOT invert
- SHL/SHR for unsigned power-of-two math
- SAR preserves sign for signed division
- ROL/ROR rotate; BT tests a bit into CF
Frequently asked questions
Is the “Bitwise and Shift Instructions” lesson free?
Yes — the full text of “Bitwise and Shift Instructions” is free to read here on the web, and the Assembly Language & x86 Low-Level Systems Programming 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 Assembly Language & x86 Low-Level Systems Programming course, upgrade to CoddyKit PRO.
What will I learn in “Bitwise and Shift Instructions”?
Master bit manipulation in x86: AND, OR, XOR, NOT, and the shift and rotate instructions used for masking, flag toggling, and fast multiplication. You practise Assembly Language & x86 Low-Level Systems Programming 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 Assembly Language & x86 Low-Level Systems Programming?
No prior experience is required. Assembly Language & x86 Low-Level Systems Programming on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Bitwise and Shift Instructions” 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 Assembly Language & x86 Low-Level Systems Programming lesson?
Yes. Every Assembly Language & x86 Low-Level Systems Programming 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
- Data Movement Instructions (MOV, PUSH, POP)
- Arithmetic and Logic Operations
- Conditional Jumps and Loops
- Bitwise and Shift Instructions