I’m trying to translate/reuse some processing code which uses shifts. (for translating 2 byte RGB to 1byte grayscale) - I am stuck.
I didn’t yet understand the difference between the shift operations.
Maybe someone could enlight me and help with the translation.
//loc is defined and (I think) doesn't matter too much for the translation int msb = packedbuf[2*loc] & 0xff; int lsb = packedbuf[2*loc+1] & 0xff; int r = (lsb >>> 3); int g = ((lsb & 0x7) << 3); g |= (msb >>> 5); int b = (msb & 0x1f); r = (r << 3)|(r >>> 2); g = (g << 2)|(g >>> 4); b = (b << 3)|(b >>> 2);
My arduino code, which is wrong as I just removed everything what didn’t seemed to be c++ bit shift related:
//l is defined and is used instead of loc from the processing code, variables are defined earlier in the code msb = 2*l; lsb = 2*l+1; r = (lsb >> 3); g = (lsb << 3); g |= (msb >> 5); b = (msb); r = (r << 3)|(r >> 2); g = (g << 2)|(g >> 4); b = (b << 3)|(b >> 2);
I am going back to wikipedia and google trying to understand the java shift operations …