containers/bitarray.bi

Summary
containers/bitarray.bi
LicenseCopyright © 2007-2011, FreeBASIC Extended Library Development Group
ext
BitArrayRepresents an arbitrarily long bitfield.
Functions
default constructorCreates a uninitialized bitfield.
constructorCreates a bitfield containing a number of bits.
issetDetermines if the specified bit is set or not.
toggleToggles the value of a certain bit.
setSets the value of a certain bit to 1 or on.
resetSets the value of a certain bit to 0 or off.
loadLoads a string containing a bitfield into memory.
dumpConverts the in memory bitfield into a binary string
sizeUsed to set the initial size of the bitfield, will not work if the num constructor is used.
Examples
BitArray and You

License

Copyright © 2007-2011, FreeBASIC Extended Library Development Group

Distributed under the FreeBASIC Extended Library Group license.  See accompanying file LICENSE.txt or copy at http://code.google.com/p/fb-extended-lib/wiki/License

ext

BitArray

Represents an arbitrarily long bitfield.  Similiar to the C++ STL class bitset in that you cannot change its size once created.

See Also

BitArray and You

Summary
Functions
default constructorCreates a uninitialized bitfield.
constructorCreates a bitfield containing a number of bits.
issetDetermines if the specified bit is set or not.
toggleToggles the value of a certain bit.
setSets the value of a certain bit to 1 or on.
resetSets the value of a certain bit to 0 or off.
loadLoads a string containing a bitfield into memory.
dumpConverts the in memory bitfield into a binary string
sizeUsed to set the initial size of the bitfield, will not work if the num constructor is used.
Examples
BitArray and You

Functions

default constructor

Creates a uninitialized bitfield.

Usage

You must first use the size method to create a bitfield.

constructor

declare constructor(byval num as SizeType)

Creates a bitfield containing a number of bits.

Parameters

numthe number of bits to allocate.

isset

declare function isset(byval bit_ as SizeType) as ext.bool

Determines if the specified bit is set or not.

Parameters

bit_the bit number (0 based) to check.

Returns

ext.bool.true if set, ext.bool.false if not, ext.bool.invalid on error.

toggle

declare sub toggle(byval bit_ as SizeType)

Toggles the value of a certain bit.

Parameters

bit_the bit number (0 based) to toggle.

set

declare sub set(byval bit_ as SizeType)

Sets the value of a certain bit to 1 or on.

Parameters

bit_the bit number (0 based) to on.

reset

declare sub reset(byval bit_ as SizeType)

Sets the value of a certain bit to 0 or off.

Parameters

bit_the bit number (0 based) to 0 or off.

load

declare sub load(byref bstring as string)

Loads a string containing a bitfield into memory.  You must first initialize the bitfield before using this procedure.  Note that all 1’s are considered 1 and anything else is 0.

Parameters

bstringstring containing the bitfield.

dump

declare function dump( ) as string

Converts the in memory bitfield into a binary string

Returns

string containing the binary dump of the bitfield.

size

declare sub size(byval num as SizeType)

Used to set the initial size of the bitfield, will not work if the num constructor is used.

Parameters

numthe size of the bitfield to create, in bits (1 based).

Examples

BitArray and You

#include once "ext/containers/bitarray.bi"
#include once "ext/strings.bi"

var bitstring = ext.strings.repeat("10", 64)
ext.strings.shuffle(bitstring)

var bitarray = ext.BitArray(len(bitstring))
bitarray.load(bitstring)
print "bits: " & bitarray.dump()

if bitarray.isset(0) then print "bit 0 is set"

bitarray.toggle(30)
bitarray.toggle(31)
bitarray.toggle(32)
print "bits: " & bitarray.dump()
declare constructor(byval num as SizeType)
Creates a bitfield containing a number of bits.
declare function isset(byval bit_ as SizeType) as ext.bool
Determines if the specified bit is set or not.
declare sub toggle(byval bit_ as SizeType)
Toggles the value of a certain bit.
declare sub set(byval bit_ as SizeType)
Sets the value of a certain bit to 1 or on.
declare sub reset(byval bit_ as SizeType)
Sets the value of a certain bit to 0 or off.
declare sub load(byref bstring as string)
Loads a string containing a bitfield into memory.
declare function dump( ) as string
Converts the in memory bitfield into a binary string
declare sub size(byval num as SizeType)
Used to set the initial size of the bitfield, will not work if the num constructor is used.