📄 cbiguint.hpp
字号:
//****************************************************
// CBIGUINT.HPP
//
// Header file for a 64 bit unsigned integer class
// Requires: CBIGUINT.CPP
//
// Designed, Written and Tested by
// Michael Potter 02/13/95
// Compuserve 70414,2121
//
// Although I retain all copyright privileges to this
// code and accompanying documentation, feel free to
// use the code in anyway you deem useful free of
// charge. I do ask that if you re-distribute the
// source code that you leave it unaltered with my
// name at the top. Future additions to and versions
// of this code may not be free. If you happen to
// find any errors, omissions or possible
// optimizations in my code I would gratefully
// appreciate a line or two on the subject. I will
// re-release the corrected code with an
// acknowledgment of your help and give you an
// unrestricted license to all upgrades and additions
// for a period of one year.
//****************************************************
#ifndef CBIGUINT_HPP
#define CBIGUINT_HPP
#define BU_DWORD_ERR (DWORD)0xFFFFFFFF
#define BU_DWORD_HIGHBIT (DWORD)0x80000000
#define BU_DWORD_LOWBIT (DWORD)0x00000001
#define BU_SAFE_STRING_SIZE (DWORD) 66
#define BU_DECIMAL (DWORD) 1
#define BU_HEXADECIMAL (DWORD) 2
#define BU_BINARY (DWORD) 4
#define BU_USE_COMMAS (DWORD) 8
class CBigUINT
{
DWORD m_high,
m_low;
public:
CBigUINT() {}
CBigUINT(const CBigUINT& bu)
{m_high = bu.m_high;m_low = bu.m_low;}
CBigUINT(DWORD low, DWORD high = (DWORD) 0)
{m_high = high;m_low = low;}
DWORD& high() {return m_high;}
DWORD& low() {return m_low;}
// Future declaration of above methods
//DWORD high() const {return m_high;}
//DWORD low() const {return m_low;}
void setTo(DWORD low, DWORD high)
{m_high = high;m_low = low;}
CBigUINT& setBit(int bitNum,BOOL on = TRUE); //0 - 63
BOOL isBitSetOn(int bitNum) const; //0 - 63
void setToError()
{m_high = m_low = BU_DWORD_ERR;}
BOOL isError() const
{return ((m_high == BU_DWORD_ERR)&&
(m_low == BU_DWORD_ERR));}
BOOL isValid() const
{return ((m_high != BU_DWORD_ERR)||
(m_low != BU_DWORD_ERR));}
CBigUINT& operator=(const CBigUINT& bu)
{m_high = bu.m_high;m_low = bu.m_low;return *this;}
CBigUINT& operator=(DWORD d)
{m_high = (DWORD) 0;m_low = d;return *this;}
BOOL operator<(const CBigUINT& bu) const;
BOOL operator>(const CBigUINT& bu) const;
BOOL operator>=(const CBigUINT& bu) const;
BOOL operator<=(const CBigUINT& bu) const;
BOOL operator==(const CBigUINT& bu) const
{return ((m_high == bu.m_high)&&
(m_low == bu.m_low));}
BOOL operator!=(const CBigUINT& bu) const
{return ((m_low != bu.m_low)||
(m_high != bu.m_high));}
BOOL operator<(DWORD d) const
{return ((m_high == 0)&&(m_low < d));}
BOOL operator>(DWORD d) const
{return ((m_high != 0)||(m_low > d));}
BOOL operator>=(DWORD d) const
{return ((m_high != 0)||(m_low >= d));}
BOOL operator<=(DWORD d) const
{return ((m_high == 0)&&(m_low <= d));}
BOOL operator==(DWORD d) const
{return ((m_high == 0)&&(m_low == d));}
BOOL operator!=(DWORD d) const
{return ((m_high != 0)||(m_low != d));}
CBigUINT operator+(const CBigUINT& bu) const;
CBigUINT operator-(const CBigUINT& bu) const;
CBigUINT operator*(const CBigUINT& bu) const;
CBigUINT divideBy(const CBigUINT bu,CBigUINT& remainder) const;
CBigUINT operator/(const CBigUINT& bu) const;
CBigUINT operator%(const CBigUINT& bu) const;
CBigUINT operator+(DWORD d) const;
CBigUINT operator-(DWORD d) const;
CBigUINT operator*(DWORD d) const;
CBigUINT divideBy(DWORD d,CBigUINT& remainder) const;
CBigUINT operator/(DWORD d) const;
CBigUINT operator%(DWORD d) const;
CBigUINT& operator+=(const CBigUINT& bu)
{*this = *this + bu;return *this;}
CBigUINT& operator-=(const CBigUINT& bu)
{*this = *this - bu;return *this;}
CBigUINT& operator*=(const CBigUINT& bu)
{*this = *this * bu;return *this;}
CBigUINT& operator/=(const CBigUINT& bu)
{*this = *this / bu;return *this;}
CBigUINT& operator%=(const CBigUINT& bu)
{*this = *this % bu;return *this;}
CBigUINT& operator+=(DWORD d)
{*this = *this + d;return *this;}
CBigUINT& operator-=(DWORD d)
{*this = *this - d;return *this;}
CBigUINT& operator*=(DWORD d)
{*this = *this * d;return *this;}
CBigUINT& operator/=(DWORD d)
{*this = *this / d;return *this;}
CBigUINT& operator%=(DWORD d)
{*this = *this % d;return *this;}
CBigUINT operator|(const CBigUINT& bu) const;
CBigUINT operator&(const CBigUINT& bu) const;
CBigUINT operator^(const CBigUINT& bu) const;
CBigUINT operator~() const;
CBigUINT& operator|=(const CBigUINT& bu)
{*this = *this | bu;return *this;}
CBigUINT& operator&=(const CBigUINT& bu)
{*this = *this & bu;return *this;}
CBigUINT& operator^=(const CBigUINT& bu)
{*this = *this ^ bu;return *this;}
CBigUINT operator<<(int numBits) const;
CBigUINT operator>>(int numBits) const;
CBigUINT& operator<<=(int numBits)
{*this = *this << numBits;return *this;}
CBigUINT& operator>>=(int numBits)
{*this = *this >> numBits;return *this;}
CBigUINT& operator++();
CBigUINT& operator--();
CBigUINT operator++(int);
CBigUINT operator--(int);
BOOL fillString(TCHAR * str,DWORD maxChars,
DWORD style= BU_DECIMAL|BU_USE_COMMAS) const ;
};
#endif //CBIGUINT_HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -