Packagenet.guttershark.util
Classpublic dynamic class BitField
InheritanceBitField Inheritance flash.utils.Proxy

The BitField class is a wrapper class that manages using an unsigned integer as a bit field. This concept is taken from C if you want to read more on the subject, look up the Programming in C book - Chapter 11 specifically.

Essentially this class allows you to store data in any part of an unsigned integer. This class manages the reading and writing from the unsigned int.

As an example, say you have two flag variables you want to track, hasPanelBeenRendered and hasXMLLoaded. Using a bitfield uses 1 unsigned integer internally, to store those two flags. So say you have this byte. 00000011. The least significant (right-most) 1 represents hasPanelBeenRendered, and the 1 in the 2's spot represents the hasXMLLoaded flag. So you can setup a bitfield to read and write those properties like so:

 
  var bf:BitField = new BitField();
  bf.addField("hasPanelBeenRendered",1,0); //1 bit, from 0 offset (right side).
  bf.addField("hasXMLLoaded",1,1); //1 bit, next bit in sequence (in the 2's spot);
  //read and write these props.
  bf.hasPanelBeenRendered = 1;
  bf.hasXMLLoaded = 1;
  

So this example is only using 1 unsigned integer internally to the bitfield, which will save on memory. It's pretty nit picky, but every "bit" helps.



Public Methods
 MethodDefined by
  
BitField(initialFieldValue:uint = 0)
Constructor for BitField instances.
BitField
  
addField(label:String, bitCount:int, bitOffset:int):void
Add a field.
BitField
  
dispose():void
Dispose of all internally used variables for managing the bit field.
BitField
Constructor detail
BitField()constructor
public function BitField(initialFieldValue:uint = 0)

Constructor for BitField instances.

Parameters
initialFieldValue:uint (default = 0) — An initial value of the entire field.

See also

Method detail
addField()method
public function addField(label:String, bitCount:int, bitOffset:int):void

Add a field.

Parameters
label:String — The property name you want to use to read and write to the field.
 
bitCount:int — The number of bits to use in the internal unsigned integer.
 
bitOffset:int — The number of bits from the right. This is an offset for each piece of information you want in different bytes of the unsigned integer.

Example
Creating and adding a field.
 
   import net.guttershark.util.BitField;
   var bf = new BitField();
   bf.addField("isOpen",4,0);
   bf.addField("isTest",4,4);
   bf.addField("anotherState",1,8);
   bf.isOpen = -16;
   bf.isTest = 15;
   bf.anotherState = 1;
   trace(bf.isOpen);
   trace(bf.isTest);
   trace(bf.anotherState);
   

dispose()method 
public function dispose():void

Dispose of all internally used variables for managing the bit field.