| This class provides utility methods for
converting byte arrays to hexidecimal Strings and manipulating BIT/BIT VARYING values as a
packed vector of booleans.
The BIT/BIT VARYING methods are modeled after
some methods in the java.util.BitSet class.
An alternative to using a SQL BIT (VARYING) column
in conjunction with the methods provided herein to
provide bit manipulation would be to use a serialized
java.util.BitSet column instead.
This class contains the following static methods:
- void set(byte[] bytes, int position) to set a bit
- void clear(byte[] bytes, int position) to clear a bit
- boolean get(byte[] bytes, int position) to get the
bit status
Since these methods effectively allow a SQL BIT to be
considered as an array of booleans, all offsets (position
parameters) are zero based. So if you want to set
the first bit of a BIT type, you would use
set(MyBitColumn, 0) .
Examples:
- SELECT BitUtil::get(bitcol, 2) FROM mytab
- UPDATE mytab SET bitcol = BitUtil::set(bitcol, 2)
- UPDATE mytab SET bitcol = BitUtil::clear(bitcol, 2)
|