Page 1 of 1

inquiry about the motion sensor example

Posted: Sat Sep 27, 2008 10:14 am
by khaled yasin
i downloaded a flow code 3 example about motion sensor,why when it measure the distance it calculates it like this
Distance = ( CaptureH << 8 ) + CaptureL why no. 8 and added to captureH???

Re: inquiry about the motion sensor example

Posted: Sun Sep 28, 2008 9:05 pm
by Sean
The Distance variable is a 16-bit integer. CaptureH and CaptureL are two 8-bit byte variables that represent the two halves of a 16-bit value.

CaptureH must be left-shifted by 8 bit positions (using << 8), equivalent to multiplication by 256, to become the high half of 16-bit value before adding to CaptureL (the low half).