Page 1 of 1

Bit Shift

PostPosted: Feb 7, 2002 @ 1:53am
by brendan
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

PostPosted: Feb 7, 2002 @ 5:21am
by brendan

PostPosted: Feb 7, 2002 @ 5:45am
by Dan East
level.fg_data[loop1][loop2] >>= 8;

Dan East

PostPosted: Feb 7, 2002 @ 6:18am
by brendan
thankyou :)

PostPosted: Feb 7, 2002 @ 12:05pm
by refractor
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.