Click or drag to resize

Bits Class

Implements an efficient array of boolean values that can also perform bit oriented operations such as AND, OR, NOT, XOR.
Inheritance Hierarchy
SystemObject
  Neon.CollectionsBits

Namespace:  Neon.Collections
Assembly:  Neon.Common (in Neon.Common.dll) Version: 2.14.0
Syntax
public class Bits

The Bits type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyIsAllOnes
Returns true if all of the bits are set to ones.
Public propertyIsAllZeros
Returns true if all of the bits are set to zeros.
Public propertyItem
Gets or sets a bit in the bitmap.
Public propertyLength
Returns the length of the bitmap.
Top
Methods
  NameDescription
Public methodAnd
Performs a bitwise and on the bits passed and the current bits and returns the result.
Public methodClearAll
Zeros all bits.
Public methodClearRange
Zeros a number of bits starting at an index.
Public methodClone
Returns a clone of the bitmap.
Public methodEquals
Determines if the bitmap passed is equal to the current bitmap.
(Overrides ObjectEquals(Object).)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Computes a hash code for the instance.
(Overrides ObjectGetHashCode.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodNot
Returns a bitmap that inverts all the bits of the current bitmap.
Public methodOr
Performs a bitwise or on the bits passed and the current bits and returns the result.
Public methodResize
Creates a new bitmap from the current instance, but resized to contain the specified number of bits.
Public methodSetAll
Sets all bits.
Public methodSetRange
Sets a number of bits starting at an index.
Public methodShiftLeft
Left shifts a bitmap by a number of positions and returns the result.
Public methodShiftRight
Right shifts a bitmap by a number of positions and returns the result.
Public methodToArray
Converts the bitmap into a boolean array.
Public methodToBytes
Converts the bitmap into an array of bytes.
Public methodToString
Renders the bitmap as a string of ones and zeros.
(Overrides ObjectToString.)
Public methodXor
Performs a bitwise xor on the bits passed and the current bits and returns the result.
Top
Operators
  NameDescription
Public operatorStatic memberBitwiseAnd
Returns the intersection of two bitmaps.
Public operatorStatic memberBitwiseOr
Returns the union of two bitmaps.
Public operatorStatic memberEquality
Determines whether two bitmaps contain the same values.
Public operatorStatic memberExclusiveOr
Returns the exclusive or of two bitmaps.
Public operatorStatic member(String to Bits)
Casts a bit string of ones and zeros into a Bits bitmap.
Public operatorStatic member(Bits to String)
Casts a Bits instance into a bit string of ones and zeros.
Public operatorStatic memberInequality
Determines whether two bitmaps do not contain the same values.
Public operatorStatic memberLeftShift
Left shifts a bitmap by a number of positions and returns the result.
Public operatorStatic memberOnesComplement
Returns the bitwise not on a bitmap.
Public operatorStatic memberRightShift
Right shifts a bitmap by a number of positions and returns the result.
Top
Remarks
Note Note
This class is similar to the .NET BitArray class. The main difference is that this class serializes the bits to a byte array as you'd expect, with bit zero being the most significant bit of the first byte, bit one being the second significant bit, etc. The BitArray class serializes the first bit to the least significant bit of the first byte.

A Bits bitmap encodes internally as an array of 32-bit integers which is much more memory efficent than how the .NET Framework would encode an array of boolean values. Use the Bits(Int32) constructor to create a zeroed bitmap with the specified number of bits, Bits(Boolean) to initialize the bitmap from a boolean array, or Bits(String) to create a bitmap from a string of ones and zeros, and Bits(Byte, Int32) to load a bitmap from a byte array serialized by a previous call to ToBytes.

You can use the indexer to get/set specific bits in the bitmap. Note that all indexes are zero-based. ClearRange(Int32, Int32) sets the specified range of bits to zero, SetRange(Int32, Int32) sets the specified range of bits to one, and ClearAll and SetAll sets all bits to the appropriate value. Resize(Int32) can be used to resize a bitmap.

The class implements the following bitwise operations: Not, And(Bits), Or(Bits), Xor(Bits), ShiftLeft(Int32), and ShiftRight(Int32). Note that the lengths of the two bitmaps passed to binary operations must be the same.

Clone returns a copy of the bitmap and ToArray converts the bitmap into a boolean array. The IsAllZeros and IsAllOnes properties can be used to determine if a bitmap is all zeros or ones and Equals(Object) can be used to determine whether two bitmaps are the same. ToString renders the bitmap as a string of 1s and 0s.

This class also defines explict casts for converting to and from a string of ones and zeros and also defines the bitwise ||, &, ~ and ^, <<, and >> operators.

See Also