Vai al contenuto principale
ProdottiStrumenti desktopTASTECADVisualizzazione disegniTASTEFILESGestione fileTASTEFTPTrasferimento fileTASTESSHSpazio di lavoro remotoTASTEZIPCompressione ed estrazioneTASTEWINMGestione fileStrumenti per sviluppatoriTASTECODEAmbiente di sviluppo integrato per RustTASTESTUDIOAmbiente integrato di sviluppo e testTASTEETLIntegrazione dati (ETL)ServerTASTEREMOTEServer di desktop remotoTASTEGEOServer geospazialeTASTEMAILSpazio di lavoro emailInvestimentiTASTESTOCKApp desktop di trading automatico azionarioIniziaDownloadDocumentazioneAcquistaTutti i prodotti
Marketplace
Notizie
TecnologiaNotizieNotizie di sviluppo di oggiDocumentazioneLinguaggi di programmazioneRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartFramework frontend webNext.jsReactVue.js · NuxtSvelteKitAngularFramework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressFramework per app e desktopTauriFlutterReact NativeElectronAlgoritmiBasi degli algoritmiAlgoritmi fondamentaliAlgoritmi avanzatiAlgoritmi pratici
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrinaGuida alla community
CollaboraTrasferimento tecnicoRealizzazione del sito webRealizzazione di app desktopPipeline di rilascio e pagamentoPartner commercialeContatti
ServiziDesktop remotoPacchetti di installazione su misura
TASTEDEV
Prodotti

Strumenti desktop

TASTECADApri con leggerezza anche i disegni più complessiTASTEFILESSolo i file che servono, alla massima velocitàTASTEFTPLa via più ordinata per i tuoi fileTASTESSHUn legame più solido tra te e i tuoi serverTASTEZIPComprimi più veloce, estrai più sicuroTASTEWINMUn file manager a due pannelli pensato per la tastiera

Strumenti per sviluppatori

TASTECODEModifica, compila, esegui il debug e testa app Rust in un'unica finestraTASTESTUDIODalla modifica ai test remoti e alle correzioni IA approvateTASTEETLSposta i dati guardando i valori

Server

TASTEREMOTEUn desktop remoto che gira sul tuo serverTASTEGEOUn server geospaziale compatibile con GeoServer, ricostruito in RustTASTEMAILRiprendi il controllo della tua posta

Investimenti

TASTESTOCKTrading automatico azionario secondo le regole che decidi tu: quando e che cosa

Inizia

DownloadUltime versioni di ogni prodottoDocsCome usare ogni prodottoAcquistaAbbonamenti e licenze perpetueTutti i prodottiTutti i prodotti a colpo d’occhio
Tutti i prodotti
MarketplaceNotizie
Tecnologia

Notizie

Notizie di sviluppo di oggiAnnunci ufficiali su linguaggi, framework, GitHub e IADocumentazioneGuide a linguaggi, framework e algoritmi

Linguaggi di programmazione

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Framework

Framework frontend webNext.jsReactVue.js · NuxtSvelteKitAngular
Framework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
Framework per app e desktopTauriFlutterReact NativeElectron

Algoritmi

Basi degli algoritmiAnalisi della complessità · Ordinamento · Ricerca · Strutture dati di base · Alberi e heapAlgoritmi fondamentaliVisita dei grafi · Cammini minimi e alberi ricoprenti · Programmazione dinamica · Algoritmi greedy · Divide et impera · BacktrackingAlgoritmi avanzatiAlgoritmi sulle stringhe · Matematica e teoria dei numeri · Manipolazione dei bit · Alberi di segmenti · Union-FindAlgoritmi praticiStrategia per colloqui di programmazione · Cache LRU · Rate limiting · Hashing consistente
Tutta la documentazione di sviluppo
Community
ProgettiScopri sviluppatori e lavoriLog di sviluppoDecisioni e lezioni appresePromptIstruzioni riutilizzabiliProblemi degli strumenti di IAProblemi e alternative di Claude, Codex, GeminiVetrinaRisultati completatiGuida alla communityCome sviluppiamo in modo aperto
Collabora
Trasferimento tecnicoApp native in Rust ed eguiRealizzazione del sito web10 lingue, account, documentazione e downloadRealizzazione di app desktopRust ed egui, senza WebViewPipeline di rilascio e pagamentoFirma, MSI, deb, rpm, AppImage, hashPartner commercialeConsigliaci e ricevi il 30%ContattiSviluppo, partnership e investimenti
Servizi
Desktop remotoRaggiungi il tuo computer dal browserPacchetti di installazione su misuraSolo il necessario, impostazioni precaricate
Acquista
IT
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Accedi
Accedi
TASTEDEV

Dai piccoli strumenti a uno sviluppo migliore.

support@tastedev.netSostieni TASTEDEV
ProdottiGamma di prodottiAcquistaDocsDownloadMarketplaceAssistenza
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrina
NormeChi siamoInformativa sulla privacyTermini di servizioCondizioni di abbonamentoRimborsiLinee guida della community
AccountAccediRegistrati
Visitatori
Oggi
Ieri
Visualizzazioni totali
Società
GXSOFT
Rappresentante
CHOI YOUNG GU
Numero di registrazione
853-44-00368
Indirizzo
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefono
+82-10-4404-1523
E-mail
whitecalvin@tastedev.net
Responsabile privacy
CHOI YOUNG GU

© 2026 TASTEDEVLe informazioni sui prodotti si basano su fonti di sviluppo verificate.Rilasciato · in miglioramento

Documentazione di Manipolazione dei bit
Manipolazione dei bit
ConceptsHow It WorksImplementationComplexityPractice ProblemsReal-World Use
Discussioni

Guida a Manipolazione dei bit · 1/6

Concepts

Per ora questo capitolo è disponibile solo in inglese.

Bit manipulation treats an integer as a row of 0s and 1s and reads or changes individual positions directly. The CPU already stores integers in binary, so AND, OR, XOR and shifts usually compile to a single instruction. That makes bit tricks fast and compact, and it lets you express sets of on/off facts in very little code. This chapter covers binary representation, two's complement, the core operators and the vocabulary used in later chapters.

Binary representation

The integer 13 is 1101 in binary. The rightmost position is bit 0, and bit i is worth 2^i, so 1101 means 8 + 4 + 0 + 1.

Bit index3210
Weight8421
Bits of 131101

Bit 0 is the least significant bit (LSB); the leftmost 1 is the most significant bit (MSB).

print(bin(13))             # 0b1101
print(format(13, "08b"))   # 00001101 (padded to 8 digits)
print(int("1101", 2))      # 13
print((13).bit_length())   # 4 bits needed

Two's complement

Almost every machine stores negative integers in two's complement: in n bits, -x is "flip every bit of x, then add 1", that is ~x + 1. With 8 bits, 5 is 00000101 and -5 is 11111011. One adder handles both signs and zero has a single encoding. An n-bit signed integer covers -2^(n-1) to 2^(n-1) - 1, so a 32-bit int runs from -2147483648 to 2147483647. A set top bit means the value is negative.

Core operators

OperationSymbolResult bit is 1 whenExample (12, 10)
AND&both bits are 11100 & 1010 = 1000 (8)
ORvertical barat least one bit is 11100, 1010 give 1110 (14)
XOR^the bits differ1100 ^ 1010 = 0110 (6)
NOT~flips every bit~12 = -13
Left shift<<bits move left, zeros enter
Domande su questo capitolo?
Capitolo successivoHow It Works
3 << 2 = 12
Right shift>>bits move right12 >> 2 = 3

x << k equals x * 2^k, and for non-negative x, x >> k equals x // 2^k. Because of two's complement, ~x == -x - 1.

a, b = 12, 10
print(a & b, a | b, a ^ b)   # 8 14 6
print(~a)                    # -13
print(3 << 2, 12 >> 2)       # 12 3
print(-12 >> 1)              # -6: arithmetic shift keeps the sign

Working with a single bit

All four basic single-bit operations use the mask 1 << i:

  • set: x | (1 << i)
  • clear: x & ~(1 << i)
  • toggle: x ^ (1 << i)
  • test: (x >> i) & 1, or (x & (1 << i)) != 0
x = 0b1010
print(bin(x | (1 << 0)))    # 0b1011
print(bin(x & ~(1 << 1)))   # 0b1000
print(bin(x ^ (1 << 3)))    # 0b10
print((x >> 3) & 1)         # 1

When to reach for it

  • Representing a set of about 20 items as one integer and visiting every subset
  • Packing many on/off states (permissions, options, feature flags) into one value
  • Fast checks: power of two, odd or even, remainder modulo 2^k via x & (2^k - 1)
  • XOR puzzles where every value appears in pairs except one

Vocabulary

  • Mask: an integer with only the bits of interest set. A mask that encodes a set is a bitmask.
  • Popcount: the number of 1 bits, also called the Hamming weight.
  • Lowest set bit: the rightmost 1, obtained with x & -x.
  • Logical vs arithmetic shift: a right shift that fills with zeros is logical; one that copies the sign bit is arithmetic.

Differences between languages

The same expression can behave differently across languages. Python integers are unbounded, so 1 << 100 is exact, and negatives act as if they had infinitely many leading 1s. JavaScript converts operands to 32-bit signed integers first, so 1 << 31 is negative and >>> 0 reads a result as unsigned. Java's int is also 32 bits, with >>> as the zero-filling shift. In C++, unsigned types keep you clear of overflow and undefined behavior. The implementation and real-world chapters cover the details.

Summary

Bit manipulation views integers as bit arrays and works on them with AND, OR, XOR, NOT and shifts. Negative numbers use two's complement, so -x == ~x + 1. Once set, clear, toggle and test feel natural and you think in masks, subset enumeration and bitmask DP follow easily.

0 commenti

Commenti principaliPrima i più recenti

Accedi · Accedi per lasciare un commento.