Hope someone could help me to solve these problems ( please show the explanation
ID: 3589286 • Letter: H
Question
Hope someone could help me to solve these problems ( please show the explanation) 1) 10101100 BITWISE-AND 00101000 12) 01101011 BITWISE-OR 11010001 You are only given operations of the follow ing four patterns: . SHIFT.. BY BITS TO THE LEFT PRODUCING.. 2. SHIFT..BY ....BITS TO THE RIGHT PRODUCING... 3. BITWISE-AND... WITH... PRODUCING... 4. BITWISE-OR WITH... PRODUCING For example, to solve a particular problem you might say: SHIFT 10100111 BY 4 BITS TO THE LEFT PRODUCINGX SHIFT 00110101 BY 2 BITS TO THE RIGHT PRODUCING Y BITWISE-AND X WITH Y PRODUCING Z BITWISE-OR Z WITH 01010101 PRODUCING THE ANSWER 14) Provide a sequence of operations that will extract the highest 4 bits from the bit-string 11011001., that is, the result of the operations will be 00001101. The result should be stored in 8-bits. (3 points) 15) Provide a sequence of operations that will take the lowest 3 bits of the bit-string 11001110 and the lowest 3 bits of the bit-string 00111111 and concatenate them together, to produce 00110111. The result should be stored in 8-bits. (3 points)Explanation / Answer
11. To solve Bitwise And operation, write both the binary numbers one below the other. Only the digits (position of number) having 1's in both the numbers can produce 1 in the result. So, answer is
10101100
00101000
00101000 - is the Result
12. To solve Bitwise OR operation, write both the binary numbers one below the other. Only the digits (position of number) having 1's in any of the numbers can produce 1 in the result. So, answer is
01101011
11010001
11111011 - is the Result.
13. To solve Bitwise XOR operation, write both the binary numbers one below the other. Only the digits (position of number) having 1's in any of the numbers can produce 1 in the result. But, if both the numbers have 1 in the same digit position, the resultant number will have a 0 in the same digit position. So, answer is
11110000
11111111
00001111 - is the Result.
14. The result can be achieved in two steps -
Step 1: BITWISE-AND 11011001 WITH 11110000 PRODUCING 11010000
Step 2: SHIFT 11010000 BY 4 BITS TO THE RIGHT PRODUCING 00001101
Explanation - Step 1 uses masking technique on the lowest 4 bits. Since for Bitwise-And, only the digits (position of number) having 1's in both the numbers can produce 1 in the result, we replace the lowest 4 bits with 0 in the second number & 1's in the highest 4 bits. Highest 4 bits are the first 4 bits from the left. So, if we write both the numbers one below the other -
11011001
11110000
11010000 - we get the result.
Step 2 - Now, the highest 4 bits though extracted needs to be represented as a number in the binary form. Since, we had used 4 digits (4 zero's) to mask the lower bits in the step above, we can just shift the digits by the same amount to the right to get the binary number representation. Each right shift will result in a 0 being added from the left, and the right-most digit is removed from the number.
15. The result can be achieved in four steps -
Step 1: BITWISE-AND 11001110 WITH 00000111 PRODUCING 00000110
Step 2: BITWISE-AND 00111111 WITH 00000111 PRODUCING 00000111
Step 3: SHIFT 00000110 BY 3 BITS TO THE LEFT PRODUCING 00110000
Step 4: BITWISE-OR 00110000 WITH 00000111 PRODUCING 00110111
Explanation - Step 1 & 2 uses masking technique on the highest 5 bits. Since for Bitwise-And, only the digits (position of number) having 1's in both the numbers can produce 1 in the result, we replace the highest 5 bits with 0 in the second number & 1's in the lowest 3 bits. Highest 5 bits are the first 5 bits from the left. So, if we write both the numbers one below the other -
11001110
00000111
00000110 - we get the result for the first number in question.
00111111
00000111
00000111 - we get the result for the second number in question.
Step 3 - Now, the lowest 3 bits though extracted from the first number (result of step 1) needs to be shifted by an equal amount of the digits in the second number's result (result of step 2) for concatenation. Since there are 3 digits in the second number's result, we can just shift the digits by the same amount to the left. Each left shift will result in a 0 being added from the right, and the left-most digit is removed from the number. Hence, we arrive at 00110000.
Step 4 - To concatenate, Bitwise OR operation is required on the results of step 2 & step 3. This will give us the desired number - 00110111
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.