
Using Bit-Wise Operations
More often than not, when working with the SPRM values, you will only be interested in
certain bits of each 16-bit value. The “bit-wise” operations (and, or, and exclusive or),
make it possible to mask the bits that are not needed, allowing you to determine the
states of the specific bits you need.
Note: You need to have a basic understanding of working with binary numbers to be
able to use these operations.
511
Chapter 20
Creating Scripts

Suppose you need to find out whether the DVD player is configured for a 4:3 or 16:9
aspect ratio monitor. To determine this, you only need to look at bits 10 and 11 of SPRM
14. You can use the “bit-wise and” operation to mask all bits except 10 and 11, making
it possible to easily determine the aspect ratio status without having to be concerned
with the other bits.
x
0
0
x
0
0
x
0
0
x
0
0
0/1
1
0/1
0/1
1
0/1
x
0
0
x
0
0
x
0
0
x
0
0
x
0
0
x
0
0
x
0
0
x
0
0
x
0
0
x
0
0
15
Bits
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
SPRM 14
And value
Result
Referring to the above table, the x’s in the SPRM 14 value represent bits that are not
needed. Bits 10 and 11 use “0/1” to indicate bits that you want to retain—these may be
set to either 0 or 1. When performing an AND operation, placing 0 in the bits you want
to mask results in their being cancelled out, regardless of their state. Placing 1 in the bits
you want to retain passes them to the result as is—a 0 is still a 0 and a 1 is still a 1. In this
case, an AND value of 3072 produces the proper masking.
The value of the result produces four possible answers: 0, 1024, 2048, and 3072. In the
case of SPRM 14, 0 indicates the DVD player is set to 4:3, and 3072 indicates it is set to
16:9 (the values of 1024 and 2048 are either not specified or reserved).