Class Hierarchy Index
Class COM.cloudscape.util.BitUtil
java.lang.Object
|
+----COM.cloudscape.util.BitUtil
- public class BitUtil
- extends Object
Copyright © 1998-1999, Cloudscape, Inc. All rights reserved.
This class provides some basic static methods for
manipulating a Cloudscape BIT or BIT VARYING field as a
packed vector of booleans. It is 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)
-
BitUtil()
-
-
clear(byte[], int)
- Clear the bit at the specified position
-
get(byte[], int)
- Check to see if the specified bit is set
-
set(byte[], int)
- Set the bit at the specified position
BitUtil
public BitUtil()
set
public static byte[] set(byte bytes[],
int position) throws Exception
- Set the bit at the specified position
- Parameters:
- bytes - the byte array
- position - the bit to set, starting from zero
- Returns:
- the byte array with the set bit
- Throws: Exception
- on bad position
clear
public static byte[] clear(byte bytes[],
int position) throws Exception
- Clear the bit at the specified position
- Parameters:
- bytes - the byte array
- position - the bit to clear, starting from zero
- Returns:
- the byte array with the cleared bit
- Throws: Exception
- on bad position
get
public static boolean get(byte bytes[],
int position) throws Exception
- Check to see if the specified bit is set
- Parameters:
- bytes - the byte array
- position - the bit to check, starting from zero
- Returns:
- true/false
- Throws: Exception
- on bad position
Class Hierarchy Index