Skip to main content

Menu

LEVEL 0
0/5 XP
HomeAboutTopicsPricingMy VaultStats

Categories

πŸ€– Artificial Intelligence
☁️ Cloud and Infrastructure
πŸ’Ύ Data and Databases
πŸ’Ό Professional Skills
🎯 Programming and Development
πŸ”’ Security and Networking
πŸ“š Specialized Topics
HomeAboutTopicsPricingMy VaultStats
LEVEL 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

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
  • Algebra Cheat Sheet
  • Descriptive Statistics Cheat Sheet
  • Graphs Cheat Sheet
  • Number Theory Cheat Sheet
View all 37 topics in Mathematics and Algorithms