#!/usr/bin/perl

# You can retrieve this module from 
# the CPAN at http://www.perl.com/CPAN/modules/by-module.
use Bit::Vector;

# Create a bit vector of size 8000.

$vector = Bit::Vector->new( 8000 );

# Set the bits 1000..2000.

$vector->Interval_Fill( 1000, 2000 );

# Clear the bits 1100..1200.

$vector->Interval_Empty( 1100, 1200 );

# Turn the bit 123 off, the bit 345 on, and toggle bit 456.

$vector->Bit_Off ( 123 );
$vector->Bit_On  ( 345 );
$vector->bit_flip( 456 );

# Test for bits.

print "bit 123 is on\n" if $vector->bit_test( 123 );

# Now we'll fill the bits 3000..6199 of $vector with ASCII hexadecimal.
# First, create set with the right size...

$fill = Bit::Vector->new( 8000 );

# fill it in from a 8000-character string...

$fill->from_string( "deadbeef" x 100 );

# and shift it left by 3000 bits for it to arrive
# at the originally planned bit position 3000.

$fill->Move_Left( 3000 );

# and finally OR the bits into the original $vector.

$vector |= $fill;

# Output the integer vector in the "String" (hexadecimal) format.

print $vector->to_String, "\n";
