bitarray_not.c (405B)
1 /* ISC license. */ 2 3 #include <skalibs/bitarray.h> 4 5 void bitarray_not (unsigned char *s, size_t a, size_t b) 6 { 7 if (!b) return ; 8 b += a ; 9 if ((a >> 3) == ((b-1) >> 3)) 10 s[a>>3] ^= ((1 << (a & 7)) - 1) ^ ((1 << (1 + (b-1 & 7))) - 1) ; 11 else 12 { 13 size_t i = (a>>3) + 1 ; 14 s[a>>3] ^= ~((1 << (a & 7)) - 1) ; 15 for (; i < (b>>3) ; i++) s[i] = ~s[i] ; 16 s[b>>3] ^= (1 << (b & 7)) - 1 ; 17 } 18 }