Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Bitwise operation
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===AND=== [[File:0...15 AND.svg|thumb|Bitwise AND of [[4-bit computing|4-bit]] integers]] A '''bitwise AND''' is a [[binary operation]] that takes two equal-length binary representations and performs the [[logical AND]] operation on each pair of the corresponding bits. Thus, if both bits in the compared position are 1, the bit in the resulting binary representation is 1 (1 Γ 1 = 1); otherwise, the result is 0 (1 Γ 0 = 0 and 0 Γ 0 = 0). For example: 010'''1''' (decimal 5) AND 001'''1''' (decimal 3) = 000'''1''' (decimal 1) The operation may be used to determine whether a particular bit is ''set'' (1) or ''cleared'' (0). For example, given a bit pattern 0011 (decimal 3), to determine whether the second bit is set we use a bitwise AND with a bit pattern containing 1 only in the second bit: 00'''1'''1 (decimal 3) AND 00'''1'''0 (decimal 2) = 00'''1'''0 (decimal 2) Because the result 0010 is non-zero, we know the second bit in the original pattern was set. This is often called ''bit masking''. (By analogy, the use of [[masking tape]] covers, or ''masks'', portions that should not be altered or portions that are not of interest. In this case, the 0 values mask the bits that are not of interest.) The bitwise AND may be used to clear selected bits (or [[Flag word|flags]]) of a [[Processor register|register]] in which each bit represents an individual [[Boolean data type|Boolean state]]. This technique is an efficient way to store a number of Boolean values using as little memory as possible. For example, 0110 (decimal 6) can be considered a set of four flags numbered from right to left, where the first and fourth flags are clear (0), and the second and third flags are set (1). The third flag may be cleared by using a bitwise AND with the pattern that has a zero only in the third bit: 0'''1'''10 (decimal 6) AND 1'''0'''11 (decimal 11) = 0'''0'''10 (decimal 2) Because of this property, it becomes easy to check the [[Parity (mathematics)|parity]] of a binary number by checking the value of the lowest valued bit. Using the example above: 0110 (decimal 6) AND 0001 (decimal 1) = 0000 (decimal 0) Because 6 AND 1 is zero, 6 is divisible by two and therefore even.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)