PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Bit Shift

Howdy, just wondering whats the easyest way to shift a high byte into the low byte..

Eg, I've a mutli-d array of numbers (signed short).. 256,512,768,1024... etc, and I want to convert them to 1,2,3,4 etc. (there is no low byte info etc)

sample code
//source is 256,512 (high byte) etc
// converted to 1, 2 etc....

level.fg_data[loop1][loop2] = level1_data[loop1][loop2];

-thanks
somthing like: (that works)

Code:

level.fg_data[loop1][loop2] >>= level1_data[loop1][loop2];
level.fg_data[loop1][loop2] >>= level.fg_data[loop1][loop2];
level.fg_data[loop1][loop2] >>= level.fg_data[loop1][loop2];
level.fg_data[loop1][loop2] >>= level.fg_data[loop1][loop2];
level.fg_data[loop1][loop2] >>= level.fg_data[loop1][loop2];
level.fg_data[loop1][loop2] >>= level.fg_data[loop1][loop2];
level.fg_data[loop1][loop2] >>= level.fg_data[loop1][loop2];
level.fg_data[loop1][loop2] >>= level.fg_data[loop1][loop2];
level.fg_data[loop1][loop2] >>= 8;

Dan East
thankyou :)
You may not want to be using the signed short (depending on what you're doing with the data)... think about using an unsigned short instead maybe.

If the data-type is signed then (IIRC), the C/C++ compiler will use *arithmetic* shifts, not *logical* shifts. This probably isn't what you want for data like bitmaps.

Cheers,

Refractor.