X-Git-Url: https://mattmccutchen.net/bigint/bigint.git/blobdiff_plain/d8a8a836449e8acd2a309cdadbe84a2de49a54be..88dbe518aa4ac1489b0d2387288c1f922fc5ea61:/BigUnsigned.hh diff --git a/BigUnsigned.hh b/BigUnsigned.hh index 0813234..f5267bb 100644 --- a/BigUnsigned.hh +++ b/BigUnsigned.hh @@ -81,7 +81,7 @@ protected: template X convertToPrimitive () const; public: - // ACCESSORS + // BIT/BLOCK ACCESSORS // Expose these from NumberlikeArray directly. NumberlikeArray::getCapacity; @@ -90,10 +90,21 @@ public: /* Returns the requested block, or 0 if it is beyond the length (as if * the number had 0s infinitely to the left). */ Blk getBlock(Index i) const { return i >= len ? 0 : blk[i]; } + void setBlock(Index i, Blk newBlock); // The number is zero if and only if the canonical length is zero. bool isZero() const { return NumberlikeArray::isEmpty(); } + /* Returns the length of the number in bits, i.e., zero if the number + * is zero and otherwise one more than the largest value of bi for + * which getBit(bi) returns true. */ + Index bitLength() const; + // Get or set bit number bi, which has value 2^bi. + bool getBit(Index bi) const { + return (getBlock(bi / N) & (1 << (bi % N))) != 0; + } + void setBit(Index bi, bool newBit); + // COMPARISONS // Compares this to x like Perl's <=>