Menu
Log in

Computer Engineering Concepts

3.5 Logic and Binary

If the 1's and 0's of a binary number are thought of as logic states, then logical operations can be performed on binary numbers. The logical operations are performed on a pair of binary numbers based on the truth table of the logical operator. The 1's and 0's of the binary numbers can be thought of as truth table entries. Imagine two single digit binary numbers with values of 1 and 1. These two numbers are identical in form to the logic states of two propositions with truth values of 1 and 1. If the binary numbers are thought of as truth values, then it is possible to apply logical operations on binary values. In this case 1 AND 1 would produce 1, and 1 OR 1 would also produce 1. This idea of logical operations on binary numbers could be extended to a pair of multi digit binary numbers by applying the logical operation on each pair of digits within the pair of numbers. Logical operations on binary should not be thought of as mathematical operations as they do not provide any mathematically meaningful results, but they do have the potential to produce mathematically meaningful results, as seen later.

Example I:        10101011 AND 1010011.

Solution:                 10101011

                         AND  01010011

                                    00000011


From this example it can be seen that the logical operator AND can be applied to two binary numbers, and a result obtained. It should be noted that this result is not the mathematical sum of the two numbers. The 0's in front are added to the smaller number to achieve the same number of bits. This addition of leading 0's does not change the value of the number.

Example II:       10101011 OR 1010011

Solution:                            10101011

                                OR         01010011

                                               11111011


In this example the OR operator is used, and the results based on the OR truth table. The OR operator creates a result that is different from the pattern of example I. Each operator will therefore give a different result. The usefulness of logical operations on binary will be seen later.

Example III:      NOT 101001010

Solution:         Result 010110101


The NOT operator as discussed earlier changes the 1's to 0's and 0's to 1's, and the result is called the complement of the binary number. This is the same as the complement discussed in chapter 2. This shows that binary numbers and logic are related.


Encryption                

Given that logical operations can be performed on binary numbers, the logical operations can be used to encrypt binary data. In chapter 2 we discussed how mathematical operations can be used to encrypt data, but now we can expand that to include logical operators as well. For example, consider the bit string 1010111110100001. To encrypt this bit string, the XOR operator and another binary sequence, called the key, is used. Here we will use the bit string 1101 as the key for encrypting the original bit string. The key is repeated until it forms a bit string with the same length as the bit string to be encrypted, in this case 1101110111011101. If the length of the original string is not a multiple of the number of bits in the key, then a part of the key is used at the end. The XOR operation is now performed using the original data bit string and the key bit string as shown below.

                    1010  1111  1010  0001

      XOR     1101  1101  1101  1101

                    0111  0010  0111  1100

The result of the logical operation becomes the encrypted version of the data string.  The encrypted string 0111001001111100 can be decrypted by applying the XOR operation with the key 1101 as shown below.

                    0111  0010  0111  1100

     XOR      1101  1101  1101  1101

                    1010  1111  1010  0001

Decryption without the key becomes very difficult to do because both the key pattern and the key length are needed to decrypt the information in the binary string.

3.6 Practice Questions

1.     Perform the AND, OR, and XOR logical operation on the following pairs of binary numbers.

        a. 1010010, 1001111                   b. 101001, 11110  

        c. 1111000, 1100101                   d. 10101111, 110101

2.     Let p represent the binary number 101000 and q 100101. Perform the following operations and determine the result.

        a. [pORq]ORp                                b. [NOTq]ANDp

        c. pXOR[NOTp]                             d. [pANDq]OR[pANDq]

3.     Encrypt the following using the XOR operator and 101 as the key.

        a. 111011010                  b. 101110001000                 c. 111001010110110

4.     Encrypt the following using the XOR operator and 1101 as the key.

        a. 100110110100           b. 100100010111                c. 1001001010100101

5.     How can a bit string be encrypted if the number of bits in the bit string is not a multiple of the number of bits in the key?

6.     Repeat question 3 with a different key and compare the two encrypted strings. 


GlobalEduTech Solutions

Powered by Wild Apricot Membership Software