use strict; use warnings; use Inline C => 'DATA'; my $vector = "\0" x 100; # Bit vector with 800 bits mytest($vector, 12); # Pass it to Inline C function print "Result:" . vec($vector, 12, 1) . "\n"; # Prints '1' __DATA__ __C__ int mytest(SV* sv_vec, unsigned int bit) { STRLEN vecbytes; // Length of vector in bytes unsigned char *myvec = (unsigned char *) SvPV(sv_vec, vecbytes); if (bit/8 >= vecbytes) return 0; // Check in range if (myvec[bit/8] & 1U<<(bit%8)) return 1; // Test if a bit is set myvec[bit/8] |= 1U<<(bit%8); // Set bit (CHANGES $vector) return 1; }