Java Reference
In-Depth Information
int alpha val = (color - val >>> 24) & 0xFF;
int red - val = (color - val >>> 16) & 0xFF;
int green - val = (color - val >>> 8) & 0xFF;
int blue - val = color - Val & 0xFF;
10.14.2 java.util.BitSet
A BitSet object represents a vector of bits whose size can grow as needed. The
bits can be used, for example, to represent a set of Boolean values. This is more
memory efficient than using a whole byte for each value as would be the case
with an array of boolean primitive types. (A JVM implementation can in fact
use bits to represent a boolean array but not all do.)
The BitSet methods might also be helpful if one is handling data in which
individual bits represent information of interest. For example, each bit might
represent the state of a relay in a large group of relays. Although internally
the JVM might represent the BitSet with an array of long values, there is
unfortunately no method in the BitSet class that converts an array of long
values into a BitSet or vice versa.
The BitSet class provides methods to access a given bit in the array with an
index value:
get (int index)
set (int index)
clear (int index)
flip (int index)
Two BitSet arrays can undergo Boolean operations:
and (BitSet bitset)
or (BitSet set)
xor (BitSet set)
andNot (BitSet set) - clears those bits in the BitSet object for which the cor-
responding bits are set in the parameter bitset object
The class includes a number of other methods such as clone() for making copies
of a BitSet , cardinality() for finding the number of bits set to one, and
nextSetBit (int fromIndex) , for finding the index of the next bit set to
one at position fromIndex or higher.
10.14.3 More bit handling
What if data from another computer platform or an external device arrives as int
or long type values but the bits actually represent float or double values?
How would we change an integer type value to the corresponding floating-point
Search WWH ::




Custom Search