Menu 

Boolean Logic and Subnet Masking

In electronics, there are several types of logical gates to handle decision making in circuits. These logic gates are built into all digital circuits and provide the basic decision making in a circuit. These are the equivalent of IF/THEN statements in programming. There are several basic functions, but the two that we will look at today are the AND function and the XOR function.  

The AND gate basically says if you want something to happen,condition 1 AND condition 2 must be met.

Like so:

Condition 1

Condition 2

Result

False

False

False

False

True

False

True

False

False

True

True

True

 

With binary numbers, 1 is considered true and 0 is considered false.

Condition 1

Condition 2

Result

0

0

0

0

1

0

1

0

0

1

1

1

 

This function is extremely useful in networking. You can use this function to compare a network address and a subnet mask to see if a packet on the network is something the computer/network device/etc. needs to react to in some way. Say you have an IP address of 192.168.1.16, and you have the very common 255.255.255.0 subnet mask.

In Binary

Address: 11000000 . 10101000 . 00000001 . 00010000

Subnet Mask: 11111111 . 11111111 . 11111111. 00000000

Using the AND function it is easy to quickly determine the network address.

11000000 . 10101000 . 00000001 . 00010000

                                  AND

11111111 . 11111111 . 11111111. 00000000

———————————————————-

11000000 . 10101000 . 00000001 . 00000000

 

In this case, the network address is 192.168.1.0. If you were to get a packet with a destination address of 192.168.2.4 the network address would be 192.168.2.0.

11000000 . 10101000 . 00000010 . 00000010

                                AND

11111111 . 11111111 . 11111111. 00000000

———————————————————–

11000000 . 10101000 . 00000010 . 00000000

 

Another basic logical function is the exclusive OR, also known as XOR. Basically this means that one condition or the other can be true,but not both.

 

Condition 1

Condition 2

Result

0

0

0

0

1

1

1

0

1

1

1

0

 

This function can be used to quickly compare the two example network addresses to see if they are on the same network. If the result is all zeroes,then the two addresses are on the same network.

Network 1: 11000000 . 10101000 . 00000001 . 00000000

XOR

Network 2: 11000000 . 10101000 . 00000010 . 00000000

————————————————————————–

Result: 00000000 . 00000000 . 00000011 . 00000000

As you can see, the results are not all zeroes, and as such, they are on different networks and won’t be able to talk directly to each other.

Submit a Comment

Pin It on Pinterest

Share This