-
Notifications
You must be signed in to change notification settings - Fork 3
/
BitBlock.java
69 lines (61 loc) · 1.42 KB
/
BitBlock.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* $Id: BitBlock.java,v 1.3 2001/10/07 23:48:55 rayo Exp $
*/
/*
* $Log: BitBlock.java,v $
* Revision 1.3 2001/10/07 23:48:55 rayo
* added author javadoc tag
*
*/
/**
* @author Ray Ontko
*/
public class BitBlock extends Block
{
/**
* Construct a bit block of the specified size in bytes.
* @param blockSize the size of the block in bytes
*/
public BitBlock( short blockSize )
{
super( blockSize ) ;
}
/**
* Set a specified bit to 1 (true).
* @param whichBit the bit to set
*/
public void setBit( int whichBit )
{
bytes[whichBit/8] |= (byte)( 1 << ( whichBit%8 ) ) ;
}
/**
* Set a specifed bit to a specified boolean value.
* @param whichBit the bit to set
* @param value the value to which the bit should be set
*/
public void setBit( int whichBit , boolean value )
{
if( value )
setBit( whichBit ) ;
else
resetBit( whichBit ) ;
}
/**
* Checks to see if the specified bit of the block is set (1) or
* reset (0).
* @param whichBit the bit to check.
* @return true if set; false if reset.
*/
public boolean isBitSet( int whichBit )
{
return ( bytes[whichBit/8] & (byte)( 1 << ( whichBit%8 ) ) ) != 0 ;
}
/**
* Sets the specified bit of the block to 0 (false).
* @param whichBit bit to set to 0 (false).
*/
public void resetBit( int whichBit )
{
bytes[whichBit/8] &= ~ (byte)( 1 << ( whichBit%8 ) ) ;
}
}