Question: Task Bitwise Operations : The bitwise operators AND, OR, and XOR are used to do bit-masking; that is, set (make 1), reset (make 0), invert

Task Bitwise Operations :

The bitwise operators AND, OR, and XOR are used to do bit-masking; that is,

set (make 1), reset (make 0), invert (toggle or flip) (from 0 to 1, or from 1 to 0) a bit (or bits) in a byte (or word).

Bit masks are strings of bits that allow for a single bitwise operation on a bit (or bits).

Commonly a bit string is 8 bits long (referred to as a byte). Conventionally, the bits in a bit string are indexed from 0 starting with LSB. Let A = XXXX XXXX2, where each X is a unique bit (0 or 1).

Task Bitwise Operations : The bitwise operators AND, OR, and XOR are

For bit-wise operations, let us consider a bit string, e.g., A = 1111 00002. We will number these bits from 0 to 7, starting from LSB. Now, suppose we want to ensure that bit 7 in A is reset (i.e., made 0).

All the other bits are left untouched. For this purpose, we now must first create a bit-mask M and select an appropriate bitwise operator O. In this example, we create our mask M as 0111 1111 and select the bitwise operator O as AND. Now we perform the operation:

A AND M = 1111 00002 AND 0111 11112 = 0111 00002

Solve the following problems by finding the appropriate bitmask M and bitwise operator O. You can also choose more than one mask and operator, such as M1, O1 and M2, O2.

Show all your working out and intermediate steps and use A = XXXX XXXX2 with your mask(s) and operator(s):

a) Set bit 0, bit 6 and leave the rest untouched.

b) Make sure that bit 3 and bit 5, and only these, are set, the others are reset.

c) Toggle the values (the opposite of what they are currently) of bits 0, 1, 2, 5, 6, 7 and reset bits 3 and 4.

Byte A Bit Position XI X 7 X 6 5 X 4 X 3 2 x 1 X 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!