Question: 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


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 staring with LSB. Let A = XXXX XXXX2, where each X is a unique bit (O or 1). Byte A Bit Position X 7 X 6 X 5 X 4 X 3 X 2 X 1 X 0 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 O). 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 Mas 01111111 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 Mi, 01 and M2, 02. 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
