Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- extern "C" void _add(unsigned int[], const unsigned int[], int);
- template<int NBits>
- class BigInt
- {
- static constexpr int m_block_count = NBits >> 5;
- unsigned int m_block[m_block_count];
- public:
- BigInt& operator=(const int imm)
- {
- m_block[0] = imm;
- for (int i = 1; i < m_block_count; ++i)
- m_block[i] = 0;
- return *this;
- }
- BigInt& operator+=(const BigInt &rhs)
- {
- _add(m_block, rhs.m_block, m_block_count);
- return *this;
- }
- BigInt operator+(const BigInt &rhs)
- {
- BigInt result = *this;
- result += rhs;
- return result;
- }
- std::ostream& operator<<(std::ostream &stream) const
- {
- for (int i = 0; i < m_block_count; ++i)
- stream << std::hex << std::setw(8) << std::setfill('0') << m_block_count;
- return stream;
- }
- private:
- friend
- std::ostream& operator<<(std::ostream &stream, const BigInt<NBits> &rhs)
- {
- for (int i = rhs.m_block_count - 1; i >= 0 ; --i)
- stream << std::hex << std::setw(8) << std::setfill('0') << rhs.m_block[i];
- return stream;
- }
- };
- int main()
- {
- BigInt<1024> a, b;
- a = 0xFFFFFFFF;
- b = 0xFFFFFFFF;
- for (int i = 0; i < 10000; ++i) {
- a += b;
- std::cout << a << std::endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment