- // Clear the unused top bits in the high word.
- void clear_unused_bits() {
- if (Size) {
- unsigned ExtraBits = Size % BITS_PER_WORD;
- Bits[Size / BITS_PER_WORD] &= ~(~0 << ExtraBits);
+ // Set the unused bits in the high words.
+ void set_unused_bits(bool t = true) {
+ // Set high words first.
+ unsigned UsedWords = NumBitWords(Size);
+ if (Capacity > UsedWords)
+ init_words(&Bits[UsedWords], (Capacity-UsedWords), t);
+
+ // Then set any stray high bits of the last used word.
+ unsigned ExtraBits = Size % BITWORD_SIZE;
+ if (ExtraBits) {
+ Bits[UsedWords-1] &= ~(~0L << ExtraBits);
+ Bits[UsedWords-1] |= (0 - (BitWord)t) << ExtraBits;