Skip to main content
ProductsDesktop toolsTASTECADDrawing reviewTASTEFILESFile managementTASTEFTPFile transferTASTESSHRemote workspaceTASTEZIPCompression and extractionTASTEWINMFile managementDeveloper toolsTASTECODERust integrated development environmentTASTESTUDIOIntegrated development and test environmentTASTEETLData integration (ETL)ServersTASTEREMOTERemote desktop serverTASTEGEOGeospatial serverTASTEMAILMail workspaceInvestingTASTESTOCKStock auto-trading desktop appGet startedDownloadsDocumentationBuyAll products
Marketplace
News
TechNewsToday's dev newsDeveloper docsProgramming languagesRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngularServer frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressApp & desktop frameworksTauriFlutterReact NativeElectronAlgorithmsAlgorithm basicsCore algorithmsAdvanced algorithmsPractical algorithms
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcaseCommunity guide
Work with usTech transferWebsite buildDesktop app buildRelease and payment pipelineSales partnerContact
ServicesRemote desktopCustom installer packages
TASTEDEV
Products

Desktop tools

TASTECADComplex drawings, opened with easeTASTEFILESJust the files you need, as fast as possibleTASTEFTPThe tidiest path for your filesTASTESSHA stronger link between you and your serversTASTEZIPPack faster, unpack saferTASTEWINMA keyboard-first file manager with two panes

Developer tools

TASTECODEEdit, build, debug and test Rust apps in one windowTASTESTUDIOFrom editing to remote tests and approved AI fixesTASTEETLMove data while you watch the values

Servers

TASTEREMOTEA remote desktop you run on your own serverTASTEGEORebuilding a GeoServer-compatible geospatial server in RustTASTEMAILTake back control of your email

Investing

TASTESTOCKStock auto-trading that follows the rules you set: when, and what

Get started

DownloadsLatest builds of every productDocsHow to use each productBuySubscriptions and perpetual licencesAll productsEvery product at a glance
All products
MarketplaceNews
Tech

News

Today's dev newsOfficial announcements on languages, frameworks, GitHub and AIDeveloper docsGuides to languages, frameworks and algorithms

Programming languages

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Web front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngular
Server frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
App & desktop frameworksTauriFlutterReact NativeElectron

Algorithms

Algorithm basicsComplexity analysis · Sorting · Searching · Basic data structures · Trees and heapsCore algorithmsGraph traversal · Shortest paths & minimum spanning trees · Dynamic programming · Greedy algorithms · Divide and conquer · BacktrackingAdvanced algorithmsString algorithms · Math and number theory · Bit manipulation · Segment trees · Union-findPractical algorithmsCoding interview strategy · LRU cache · Rate limiting · Consistent hashing
All development docs
Community
ProjectsDiscover builders and their workDevelopment logsDecisions and lessons learnedPromptsReusable instructionsAI tool issuesProblems and workarounds for Claude, Codex, GeminiShowcaseFinished resultsCommunity guideHow we build in the open
Work with us
Tech transferNative apps in Rust and eguiWebsite build10 languages, accounts, docs and downloadsDesktop app buildRust and egui, no WebViewRelease and payment pipelineSigning, MSI, deb, rpm, AppImage, hashesSales partnerRecommend us and earn 30%ContactBuilds, partnerships and investment
Services
Remote desktopReach your computer from a browserCustom installer packagesOnly the features you need, settings preloaded
Buy
EN
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Log in
Log in
TASTEDEV

From small tools to better development.

support@tastedev.netSupport TASTEDEV
ProductsProduct lineupBuyDocsDownloadsMarketplaceSupport
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcase
PoliciesAbout usPrivacy policyTerms of serviceSubscription termsRefund policyCommunity guidelines
AccountLog inSign up
Visitors
Today
Yesterday
Total views
Company
GXSOFT
Representative
CHOI YOUNG GU
Business registration number
853-44-00368
Address
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Phone
+82-10-4404-1523
Email
whitecalvin@tastedev.net
Privacy officer
CHOI YOUNG GU

© 2026 TASTEDEVProduct information is based on verified development sources.Released · improving

Developer docs
Bit manipulation
Bit manipulationReference implementationStep-by-step guideOfficial docs and resourcesDiscussionsComments

Other algorithms

Algorithm basics5
Complexity analysisSortingSearchingBasic data structuresTrees and heaps
Core algorithms6
Graph traversalShortest paths & minimum spanning treesDynamic programmingGreedy algorithmsDivide and conquerBacktracking
Advanced algorithms4
String algorithmsMath and number theorySegment treesUnion-find
Practical algorithms4
Coding interview strategyLRU cacheRate limitingConsistent hashing

Algorithm

Bit manipulation

Bit manipulation treats integers as binary digits and uses AND, OR, XOR and shifts to handle sets, flags and bitmask DP quickly and compactly.

Start the guideDiscussions

Bit manipulation views an integer as a row of 0s and 1s and uses AND, OR, XOR, NOT and shifts to read, set, clear and flip individual bits. Computers store integers in binary and negative numbers in two's complement, so these operations usually map to a single CPU instruction. A short expression such as x & -x (the lowest set bit) or x & (x - 1) (that bit cleared) can replace an entire loop.

It matters because one integer can represent a set of about 20 items, which makes it easy to visit every subset and to use sets as states in bitmask dynamic programming. Coding interviews regularly feature subset enumeration, XOR properties and popcount, and production code relies on bits for file permissions, feature flags, subnet math, hash tables and bitmap indexes. The rules differ by language, though: Python integers are unbounded, JavaScript converts operands to 32 bits and has >>>, Java also has >>>, and C++ expects unsigned types for safe masks.

Start by converting numbers to binary and two's complement by hand. Then practice the four single-bit operations (set, clear, toggle, test) and print every subset by looping a mask from 0 to 2^n - 1. Move on to submask enumeration and bitmask DP problems such as job assignment or the traveling salesman problem, and finally check the integer width and shift rules of the languages you use.

On this page

  1. Highlights
  2. Where it is used
  3. Reference implementation
  4. Step-by-step guide
  5. Official docs and resources
  6. Discussions
  7. Comments

Highlights

Two's complement and shifts

Negative numbers are stored by flipping every bit and adding 1. Left shifts multiply by 2, right shifts divide by 2, and languages differ on arithmetic versus logical right shifts.

Single-bit operations

With the mask 1 << i, OR sets bit i, AND NOT clears it and XOR toggles it. x & -x isolates the lowest set bit and x & (x - 1) removes it.

Sets as bitmasks

The subsets of n items correspond one-to-one with the integers 0 to 2^n - 1, and union, intersection and difference each take a single bitwise operation.

Popcount and XOR tricks

Count set bits by repeating x &= x - 1 or with a built-in. Because a ^ a = 0, XOR finds the unpaired value and yields Hamming distances and Gray codes.

Where it is used

  • Subset enumeration and bitmask DP in coding interviews
  • Permission and feature flags
  • Subnet calculations and hash table indexing
  • Bitsets, Bloom filters and bitmap indexes

Reference implementation

Subset enumeration and popcount

popcount counts set bits by clearing the lowest one with x &= x - 1 until nothing is left. subsets loops a mask from 0 to 2^n - 1 and picks the items whose bit is set, producing every subset. The last line shows 12 & -12 = 4 (the lowest set bit), 12 & 11 = 8 (that bit cleared) and x ^ x = 0. Run it with python bit_manipulation.py.

bit_manipulation.py

def popcount(x: int) -> int:
    count = 0
    while x:
        x &= x - 1  # clear the lowest set bit
        count += 1
    return count


def subsets(items):
    n = len(items)
    for mask in range(1 << n):
        yield mask, [items[i] for i in range(n) if (mask >> i) & 1]


for mask, chosen in subsets(["a", "b", "c"]):
    print(format(mask, "03b"), popcount(mask), chosen)

x = 12
print(x & -x, x & (x - 1), x ^ x)  # 4 8 0
python bit_manipulation.py

Step-by-step guide

Six chapters that take you from installation to the core ideas of Bit manipulation.

  1. Concepts
  2. How It Works
  3. Implementation
  4. Complexity
  5. Practice Problems
  6. Real-World Use

Official docs and resources

  • OfficialBitwise Operations on Integer Types
  • LearnBit manipulation
  • LearnEnumerating submasks of a bitmask
  • ReferenceBitwise operation
  • ReferenceTwo's complement
  • ReferenceUnsigned right shift (>>>)
  • Referencestd::popcount
  • CommunityBit Twiddling Hacks

Discussions

Start a discussion

Ask questions, share experience and trade opinions about Bit manipulation.

No discussions yet. Start the first one.

0 comments

Top commentsNewest first

Sign in · Sign in to leave a comment.