Please Whitelist This Site?

I know everyone hates ads. But please understand that I am providing premium content for free that takes hundreds of hours of time to research and write. I don't want to go to a pay-only model like some sites, but when more and more people block ads, I end up working for free. And I have a family to support, just like you. :)

If you like The TCP/IP Guide, please consider the download version. It's priced very economically and you can read all of it in a convenient format without ads.

If you want to use this site for free, I'd be grateful if you could add the site to the whitelist for Adblock. To do so, just open the Adblock menu and select "Disable on tcpipguide.com". Or go to the Tools menu and select "Adblock Plus Preferences...". Then click "Add Filter..." at the bottom, and add this string: "@@||tcpipguide.com^$document". Then just click OK.

Thanks for your understanding!

Sincerely, Charles Kozierok
Author and Publisher, The TCP/IP Guide


NOTE: Using software to mass-download the site degrades the server and is prohibited.
If you want to read The TCP/IP Guide offline, please consider licensing it. Thank you.

The Book is Here... and Now On Sale!

Searchable, convenient, complete TCP/IP information.
The TCP/IP Guide

Custom Search







Table Of Contents  The TCP/IP Guide
 9  Networking Fundamentals
      9  Backgrounder: Data Representation and the Mathematics of Computing

Previous Topic/Section
Boolean Logic and Logical Functions
Previous Page
Pages in Current Topic/Section
12
3
Next Page
The Open System Interconnection (OSI) Reference Model
Next Topic/Section

Bit Masking (Setting, Clearing and Inverting) Using Boolean Logical Functions
(Page 3 of 3)

Inverting Groups of Bits Using the XOR Function

There are also situations in which we want to invert some bits; that is, change a one value to a zero, or a zero value to a one. To do this, we use the XOR function. While this is not as intuitive as the way masking works with OR and AND, if you refer to the XOR truth table (Table 13) you will see that if you XOR with a one, the input value is flipped, while XORing with a zero causes the input to be unchanged. To see how this works, let's take the same input example and invert the middle six bits, as shown in Table 16.


Table 16: Inverting Bits Using an XOR Bit Mask

Input

1

0

1

0

0

1

0

1

1

0

1

0

Mask

0

0

0

1

1

1

1

1

1

0

0

0

Result of XOR Operation

1

0

1

1

1

0

1

0

0

0

1

0


In the world of networking, bit masking is most commonly used for the manipulation of addresses. In particular, masking is perhaps best known for its use in differentiating between the host and subnetwork (subnet) portions of Internet Protocol (IP) addresses, a process called subnet masking and described in the section on IP subnet addressing.

Note: Masks are often expressed in either hexadecimal or decimal notation for simplicity of expression, as shown in the IP subnetting summary tables. However, the masks are always applied in binary, as described above. You should convert the mask to binary if you want to see exactly how the masking operation is going to work.


Key Concept: The properties of the OR and AND boolean functions make them useful when certain bits of a data item need to be set (changed to 1) or cleared (changed to 0), a process called bit masking. To set bits to one, a mask is created and used in a bit-by-bit OR with the input; where the mask has a value of 1, the bit is forced to a 1, while each 0 bit leaves the corresponding original bit unchanged. Similarly, a mask used with AND clears certain bits; each 1 bit in the mask leaves the original bit alone, while each 0 forces the output to 0. Finally, XOR can be used to invert selected bits using a mask.


 


Previous Topic/Section
Boolean Logic and Logical Functions
Previous Page
Pages in Current Topic/Section
12
3
Next Page
The Open System Interconnection (OSI) Reference Model
Next Topic/Section

If you find The TCP/IP Guide useful, please consider making a small Paypal donation to help the site, using one of the buttons below. You can also donate a custom amount using the far right button (not less than $1 please, or PayPal gets most/all of your money!) In lieu of a larger donation, you may wish to consider purchasing a download license of The TCP/IP Guide. Thanks for your support!
Donate $2
Donate $5
Donate $10
Donate $20
Donate $30
Donate: $



Home - Table Of Contents - Contact Us

The TCP/IP Guide (http://www.TCPIPGuide.com)
Version 3.0 - Version Date: September 20, 2005

Copyright 2001-2005 Charles M. Kozierok. All Rights Reserved.
Not responsible for any loss resulting from the use of this site.