समय/संख्याएं
बिटवाइज़ ऑपरेशन
दी गई रेंज (8/16/32/64 बिट) के इंटीजर पर AND/OR/XOR/NAND/NOR/XNOR/NOT और शिफ्ट, किसी भी नंबर सिस्टम में।
(शिफ्ट किए जाने वाले बिट्स की संख्या, डेसिमल नंबर)
Bitwise operations work directly on a number's individual bits rather than its value as a whole — the basis for permission flags, network protocols, and low-level optimization.
How to use it
- Enter one or two numbers in any base (binary, hex, decimal) and pick an operation (AND, OR, XOR, NAND, NOR, XNOR, NOT, or a shift).
- Pick a bit width (8/16/32/64 bits) — it affects how NOT and shifts behave at the number's boundaries.
- The result is shown instantly in several number bases for easy comparison.
Common uses
- Working with permission or setting flags packed into a single number (file system access rights, for example).
- Debugging a network protocol or binary format where fields are packed at the individual-bit level.
- A teaching example for understanding binary number representation and operations on it.
Things to keep in mind
The result of NOT and shifts depends on the chosen bit width — the same number gives a different result at 8-bit versus 32-bit width because of the different number of bits involved.
XOR is often used to toggle a flag — applying XOR twice with the same value returns the original.
इस टूल के बारे में लेख: बिटवाइज़ ऑपरेशन: बिट लेवल पर AND, OR और XOR कैसे काम करते हैं
अक्सर पूछे जाने वाले प्रश्न
AND, OR, XOR, NAND, NOR, XNOR और NOT में क्या अंतर है?
AND तभी 1 देता है जब दोनों बिट्स 1 हों, OR तब 1 देता है जब कम से कम एक 1 हो, और XOR तब 1 देता है जब बिट्स अलग हों। NAND/NOR/XNOR इनके निषेध हैं, और NOT एकल ऑपरेंड के हर बिट को उलट देता है।
संख्या की बिट चौड़ाई और चिह्न कैसे संभाला जाता है?
8/16/32/64 बिट्स की चौड़ाई चुनें — ऑपरेशन्स और शिफ्ट्स उसी सीमा में होते हैं। ऋणात्मक संख्याएं टू'ज़ कॉम्प्लीमेंट में दर्शाई जाती हैं, इसलिए NOT या शिफ्ट का परिणाम अप्रत्याशित लग सकता है अगर आप दशमलव नोटेशन के आदी हैं।
लेफ्ट शिफ्ट और राइट शिफ्ट में क्या अंतर है?
लेफ्ट शिफ्ट (<<) दाईं तरफ शून्य जोड़ता है, प्रभावी रूप से शिफ्ट मात्रा की घात में 2 से गुणा करता है। राइट शिफ्ट लॉजिकल (बाईं तरफ शून्य जोड़ता है) या अरिथमेटिक (साइन बिट सुरक्षित रखता है) हो सकता है — प्रकार चुने गए मोड पर निर्भर करता है।
"if (a & b == c)" जैसा एक्सप्रेशन अक्सर उम्मीद के मुताबिक क्यों काम नहीं करता?
ज़्यादातर लैंग्वेजेस में तुलना ऑपरेटर == की प्रायोरिटी बिटवाइज़ & से ज़्यादा होती है, इसलिए एक्सप्रेशन "a & (b == c)" की तरह गणना होता है, न कि जैसा लेखक आमतौर पर उम्मीद करता है। इस जाल से बचने के लिए बिटवाइज़ ऑपरेशन्स को हमेशा स्पष्ट कोष्ठकों में रखें।
अलग-अलग बूलियन वेरिएबल्स की जगह बिटवाइज़ फ्लैग्स का इस्तेमाल क्यों किया जाता है?
एक ही संख्या में फ्लैग्स का सेट स्टोर और ट्रांसमिट करना ज़्यादा कॉम्पैक्ट होता है (जैसे नेटवर्क प्रोटोकॉल या फ़ाइल फ़ॉर्मैट में), और AND/OR/XOR के ज़रिए किसी ख़ास फ्लैग को जांचना या बदलना एक तेज़ ऑपरेशन में हो जाता है।