Question: I'm so close to finishing this program but am a bit confused with this part: Please help!!!!!!! Calling decode restores an image in which each
I'm so close to finishing this program but am a bit confused with this part: Please help!!!!!!!
Calling decode restores an image in which each pixel has had the upper six bits negated. To unscramble the image, your code should negate them again. You can use bitwise operators, as shown below:
original pixel = 115 = 0b01110011
upper value = 115 & 0b11111100 = 0b01110000 (upper six bits of original)
lower value = 115 & 0b00000011 = 0b00000011 (lower two bits of original)
negate upper value = ~upper & 0b11111100 = 0b10001100
new pixel = upper | lower = 0b10001100 | 0b00000011 = 0b10001111 = 143
Calling swap restores an image in which each pixel has been scrambled by exhanging the lower 2 bits with the upper 2 bits. To do this requires that your code do the same exchange to restore the original pixel. Don't modify the middle four bits. By far the easiest way to do this is to use the bitwise operators. Here's an example for your testing:
original pixel = 114 = 0b01110010
upper two bits of original = 0b01110010 & 0b11000000 = 0b01000000
middle four bits of original = 0b01110010 & 0b00111100 = 0b00110000
lower two bits of original = 0b01110010 & 0b00000011 = 0b00000010
new pixel = (lower << 6) | middle | (upper >> 6) = 0b10110001 = 177
Calling mirror reverses the image left to right. To reverse left to right, exchange the first column for the last column, the second column for the second to last column, and so on until the entire image is reversed.
Calling exchange swaps the image area defined by a rectangle with width 200 and height 300 starting at row index 20 and column index 20 for a rectangle of the same size starting at row index 20, and column index 280.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
