21 - Bitwise manipulation and masks

 1. Bitwise operations are similar to Boolean logic operations except that they work on individual bits in a byte rather than on whole codes or characters



 2. The application and use of bitwise manipulation and masks include:

  use in packet switching and networks (the internet)

  All of the above! This topic is a very 'hot' one in Computer Science

  use in embedded systems and games

  use in graphics

 3. Bitwise Operations are faster and closer to the system and sometimes are able to really help with program optimisation.



 4. Identify the process using logical operators to normalise a floating point number

  Mask with 01000… using AND to see if second digit is 1. Shift left 1 if not the case and repeat until it is.

  Mask with 01000 using OR to see if second digit is 1.Shift right 1 if not.

  None of the above

  Mask with 111111 using OR to se if the second digit is 0. Shift left 1.

 5. Interrupts from various sources are stored as bits in a binary value. How can logical operations be used to identify whether a specific interrupt has been generated?

  None of the above

  Mask the interrupt using AND and a mask with 1 in the appropriate place, 0s elsewhere.

  Mask the interrupt using AND and a mask with 0 in the correct place with 0s elsewhere

  Mask the interrupt using OR and a mask with 0 in the appropriate place, 1s elsewhere

 6. The image below shows a list of the bitwise operators. What does the bitwise AND operator do?

  The AND operator simply adds two bits together

  None of the above

  The AND operator acts as a bridge and concatenates two bits together

  The AND operator compares 2 bits. If they are both 1, then the result is 1, otherwise the result is 0

 7. Bitwise operators can check the status of 'flags'. A flag is simply an indicator of whether something is ____________ or is used to indicate whether something has happened or not

  None of the above

  below or above a certain numeric value of bits

  coloured or transparent


 8. We can use bitwise operators to perform some Maths tasks, as SHIFT RIGHT has the effect on a number of _________________

  multiplying it by 2

  adding it to 2

   dividing it by 2.

  subtracting 2 from it

 9. SHIFT LEFT has the effect of ______________

   dividing it by 2.

  subtracting 2 from it

  multiplying it by 2

  adding it to 2

 10. The 'shifting of bits' is used in the algorithm known as MD5, which is used to verify that a file has not been corrupted



 11. Another use of bitwise operators is to quickly clear out a register. This can easily be achieved by ANDing a 16-bit register with ________________

  the binary sequence: 001

  the binary sequence: 0000 0000 0000 0000

  the binary sequence: 1010101010101010101010101

  the binary sequence: 111

 12. A mask is a _________________________, which allows specific bits in a piece of data to be tested or altered.

  specific type of operator (usually an XOR)

  None of the above

  way of hiding bit patterns so that they do not corrupt a file

   bit pattern that has been defined by a programmer

 13. With a single left shift, each bit is moved up one location with the leftmost bit discarded (the MSB) and a _______________________

  zero pads out the MSB (most significant bit)

  None of the above

  one or two pads out the right most bit (the LSB)

  zero pads out the rightmost bit (the LSB)

 14. With logical shifts, the sign is always preserved. The sign is never discarded under any circumstances.



 15. A popular use of masking is with ________________. The 'subnet mask' extracts the network address of a device from its IP address.

  IP addressing

  packet switching

  TCP protocol identification

  network theft protection

 16. If a device has an IP address of and the subnet mask is, then applying an 'AND' to these two numbers (in binary) will return:

  192.168.2 which will be the network address of the device

  An error message which will tell us that the device is not on the network

  None of the above which is the result of the 'AND' bitwise operator

 17. With a circular shift, the MSB is copied into the LSB and the bit is then multiplied by 10.



 18. An OR bit set is useful to set a bit within a word or byte without regard to the other bits.



 19. If a programmer has stored 8 independent flags in a byte, 1001 0000 and wants to set the 2nd and 3rd bits from the left. He could apply:

  the bit pattern: 0000 1111 to it with an OR operation

  the bit pattern: 1001 1111 to it with an OR operation

  the bit pattern: 0110 0000 to it with an OR operation

  the bit pattern: 1111 1110 to it with an OR operation

 20. The Binary XOR: copies the bit if it is set in one operand but not both



 21. Bitwise operators operate on numbers (normally), but instead of treating that number as if it were a single value, they treat it as if it were ______________________

  a string of bytes, written in sign and magnitude

  None of the above

  a string of bits, written in twos-complement binary.

  a string of 1s and 0s, up to a maximum of 4 bits

 22. Create a mask to reverse the first four bits of a value, leaving the last four bits in their original state. State which logical operation is required.

  Answer: 11110000 with XOR

  Answer: 00001111 with XOR

  Answer 00101111 with AND

  Answer: 10101111 with OR

 23. Identify the process using logical operators to create a two’s complement of a binary value.

  None of the above

  XOR with 11111111 and add 1.

  XOR with 00001111

  XOR with 11110000 add 10

 24. What is this describing? "Mask with 01000… using AND to see if second digit is 1. Shift left 1 if not the case and repeat until it is"

  describing how bitwise operations can be used to normalise a floating point binary number.

  None of the above

  describing the use of a bitwise operation on a mask

  describing how a floating point binary number can be masked using operators