Skip to main content

Menu

LEVEL 0
0/5 XP
HomeAboutTopicsPricingMy VaultStatsPractice TestsCertifications

Categories

🎓 Certifications
🤖 Artificial Intelligence
☁️ Cloud and Infrastructure
💾 Data and Databases
💼 Professional Skills
🎯 Programming and Development
🔒 Security and Networking
📚 Specialized Topics
CheatGrid
HomeAboutTopicsPricingMy VaultStatsPractice TestsCertifications
LVLEVEL 0
0/5 XP
GitHub
© 2026 CheatGrid™. All rights reserved.
Privacy PolicyTerms of UseAboutContact

Bit Manipulation and Bitwise Operations Cheat Sheet

Bit Manipulation and Bitwise Operations Cheat Sheet

Back to Mathematics and Algorithms
Updated 2026-05-19
Next Topic: Blockchain Basics Cheat Sheet

Bitwise operations work directly on the binary representation of integers, enabling compact data encoding, high-performance algorithms, and low-level hardware control. Mastering the seven core operators—AND, OR, XOR, NOT, left shift, arithmetic right shift, and logical right shift—unlocks a toolkit of O(1) tricks: toggling flags, isolating bits, counting set bits in O(k), detecting power-of-two values, implementing branchless arithmetic, and solving classic problems (missing number, XOR swap, Gray code). Two's complement representation ties everything together, making signed-integer arithmetic consistent with unsigned bit patterns in nearly every modern language and CPU architecture.


What This Cheat Sheet Covers

This topic spans 12 focused tables and 156 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.

Table 1 — Binary Representation FundamentalsTable 2 — Core Bitwise OperatorsTable 3 — Set / Clear / Toggle / Check BitsTable 4 — XOR Properties and Key IdentitiesTable 5 — Power-of-Two and Rightmost-Bit TricksTable 6 — Counting and Locating BitsTable 7 — Shift Operations Deep DiveTable 8 — Bitmask and Flag TechniquesTable 9 — Branchless Arithmetic TricksTable 10 — XOR-Based AlgorithmsTable 11 — Language-Specific Behavior and Built-insTable 12 — Real-World Applications

Table 1 — Binary Representation Fundamentals

Before any bit trick makes sense you need a firm grasp of how integers are actually laid out in memory. These rows cover the building blocks—unsigned versus two's complement, where the sign bit lives, what -1 and INT_MIN look like in raw bits, and how sign extension, hex notation, and endianness shape the bytes you'll be manipulating.

ConceptExampleDescription
Unsigned binary
0b1011 = 11
• Each bit k contributes 2^k
• value always ≥ 0
Two's complement (positive)
0b0110 = +6
• MSB = 0 → positive
• value = normal binary
Two's complement (negative)
0b1010 = −6 (8-bit)
• MSB = 1 → negative
• value = −(~n + 1)
Negate in two's complement
~n + 1
Flip all bits then add 1
One's complement
~0b0110 = 0b1001
• All bits flipped
• has +0 and −0 (not used in modern CPUs)
Sign bit (MSB)
bit 31 in int32
0 = positive, 1 = negative
−1 representation
0xFFFFFFFF (32-bit)
• All bits set
• universal across widths

More in Mathematics and Algorithms

  • Big O Notation Cheat Sheet
  • Blockchain Basics Cheat Sheet
  • Abstract Algebra Essentials Cheat Sheet
  • Convex Optimization Cheat Sheet
  • Hash Tables and Hash Maps Cheat Sheet
  • Number Theory Cheat Sheet
View all 57 topics in Mathematics and Algorithms