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!

The whole site in one document for easy reference!
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
1
2
3
Next Page
The Open System Interconnection (OSI) Reference Model
Next Topic/Section

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

Clearing Groups of Bits Using the AND Function

To clear a certain pattern of bits, you do a similar masking operation, but using the AND function instead. If you AND a bit with zero, it will clear it to zero regardless of what the bit was before, while ANDing with one will leave the bit unchanged. So, to take the same example above and clear the middle six bits, we AND with the reverse bit mask, 111000000111. This is shown in Table 15 and illustrated in Figure 10.


Figure 10: Clearing Bits Using an AND Bit Mask

This diagram shows how a bit mask can be used to clear certain bits in a binary number while preserving others. The mask shown here can be likened to a painter’s mask; each 1 represents a “transparent” area that keeps the corresponding input bit value, while each 0 is a bit where the original value is to be cleared. After performing an AND on each bit pair, the first three and last three bits are preserved while the middle six, since they were each ANDed with 0, are forced to 0 in the output.

 



Table 15: Clearing Bits Using an AND Bit Mask

Input

1

0

1

0

0

1

0

1

1

0

1

0

Mask

1

1

1

0

0

0

0

0

0

1

1

1

Result of AND Operation

1

0

1

0

0

0

0

0

0

0

1

0


We can also look at this “clearing” function a different way. We are clearing the bits where the mask is a zero, and in so doing “selecting” the bits where the mask is a one. Thus, ANDing with a bit mask means that you “keep” the bits where the mask is a one and “remove” the bits where it is a zero.


Previous Topic/Section
Boolean Logic and Logical Functions
Previous Page
Pages in Current Topic/Section
1
2
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.