Download ACS Color 320 x 240 LCD Basic Programming

Transcript
ACS Color 320 x 240 LCD Basic Programming Manual
8 September 2014
The bitwise & operator is often used to mask off or clear some set of bits. This can be used to determine
which bits are set by &’ing a value with the mask of the bit to examine. So the value 1234 bitwise & with
255 is 210:
Decimal
1234
& 255
= 210
15
0
0
0
14
0
0
0
13
0
0
0
12
0
0
0
11
0
0
0
10
1
0
0
9
0
0
0
8
0
0
0
7
1
1
1
6
1
1
1
5
0
1
0
4
1
1
1
3
0
1
0
2
0
1
0
1
1
1
1
0
0
1
0
The bitwise | operator is used to turn on or set some set of bits. So the value 1234 bitwise | with 255 is
1279:
Decimal
1234
| 255
= 1279
15
0
0
0
14
0
0
0
13
0
0
0
12
0
0
0
11
0
0
0
10
1
0
1
9
0
0
0
8
0
0
0
7
1
1
1
6
1
1
1
5
0
1
1
4
1
1
1
3
0
1
1
2
0
1
1
1
1
1
1
0
0
1
1
The bitwise exclusive or operator ^ sets a one in each bit position where its operands have different
bits, and zero where they are the same. This can be used to toggle specific bits by ^’ing a value with the
bits to toggle. So the value 1234 ^ with 255 is 1069:
Decimal
1234
^ 255
= 1069
15
0
0
0
14
0
0
0
13
0
0
0
12
0
0
0
11
0
0
0
10
1
0
1
9
0
0
0
8
0
0
0
7
1
1
0
6
1
1
0
5
0
1
1
4
1
1
0
3
0
1
1
2
0
1
1
1
1
1
0
0
0
1
1
The bitwise << and >> perform left and right shifts of their left operand by the number of bit positions
given by their right operand, which must be positive. Vacated bits on the right are filled by zeroes, vacated
bits on the left are filled with the value of the sign bit.
The bitwise << shifts the bits towards the left from LSB towards MSB, filling in the vacated LSB
positions with zero bits. Thus 1234 << 2 = 4936:
Decimal
1234
<< 2
= 4936
15
0
←
0
14
0
←
0
13
0
←
0
12
0
←
1
11
0
←
0
10
1
←
0
9
0
←
1
8
0
←
1
7
1
←
0
6
1
←
1
5
0
←
0
4
1
←
0
3
0
←
1
2
0
←
0
1
1
←
0
0
0
←
0
← 0, 0
The bitwise >> shifts the bits towards the right from MSB towards LSB, filling in the vacated MSB
positions with copies of the sign bit 15. Thus1234 >> 2 = 308:
Decimal
1234
>> 2
= 308
0, 0 →
15
0
→
0
14
0
→
0
13
0
→
0
12
0
→
0
11
0
→
0
10
1
→
0
9
0
→
0
8
0
→
1
7
1
→
0
6
1
→
0
5
0
→
1
4
1
→
1
3
0
→
0
2
0
→
1
1
1
→
0
0
0
→
0
Since the bits filling into the vacated MSB positions are copies of the sign bit, bit 15 then -1234 >> 2 =
-308:
Decimal
-1234
>> 2
= -308
1, 1 →
15
1
→
1
14
1
→
1
13
1
→
1
Copyright©2010-2014 by ACS, Sarasota, Florida
12
1
→
1
11
1
→
1
10
0
→
1
119
9
1
→
1
8
1
→
0
7
0
→
1
6
0
→
1
5
1
→
0
4
0
→
0
3
1
→
1
2
1
→
0
1
1
→
1
0
0
→
1
ALL RIGHTS RESERVED