⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uint128.h

📁 网络socket,IO,线程池
💻 H
字号:
#ifndef _M_UNSIGNED_INT_128_2004_8_5_ZHY_H
#define _M_UNSIGNED_INT_128_2004_8_5_ZHY_H

#include <string>
using namespace std;

namespace CommonInclude {

class CUInt128 
{
public:
	typedef unsigned long ULONG;
	CUInt128();
	CUInt128(ULONG value);
	CUInt128(const byte *valueBE);
	/**
	 * Generates a new number, copying the most significant 'numBits' bits from 'value'.
	 * The remaining bits are randomly generated.
	 */
	CUInt128(const CUInt128 &value, unsigned int  numBits = 128);

	const byte* getData() const { return (byte*)m_data; }
	byte* getDataPtr() const { return (byte*)m_data; }

	/** Bit at level 0 being most significant. */
	unsigned int  getBitNumber(unsigned int  bit) const;
	int compareTo(const CUInt128 &other) const;
	int compareTo(ULONG value) const;

	void toHexString(CString& str) const;
	void toBinaryString(CString& str, bool trim = false) const;
	void toByteArray(byte *b) const;

	ULONG get32BitChunk(int val) const {return m_data[val];}

	CUInt128& setValue(const CUInt128 &value);
	CUInt128& setValue(ULONG value);
	CUInt128& setValueBE(const byte *valueBE);

	CUInt128& setValueRandom(void);
	CUInt128& setValueGUID(void);

	CUInt128& setBitNumber(unsigned int  bit, unsigned int  value);
	CUInt128& shiftLeft(unsigned int  bits);

	CUInt128& add(const CUInt128 &value);
	CUInt128& add(ULONG value);
	CUInt128& subtract(const CUInt128 &value);
	CUInt128& subtract(ULONG value);

	CUInt128& xor(const CUInt128 &value);
	CUInt128& xorBE(const byte *valueBE);

	void operator+  (const CUInt128 &value) {add(value);}
	void operator-  (const CUInt128 &value) {subtract(value);}
	void operator=  (const CUInt128 &value) {setValue(value);}
	bool operator<  (const CUInt128 &value) const {return (compareTo(value) <  0);}
	bool operator>  (const CUInt128 &value) const {return (compareTo(value) >  0);}
	bool operator<= (const CUInt128 &value) const {return (compareTo(value) <= 0);}
	bool operator>= (const CUInt128 &value) const {return (compareTo(value) >= 0);}
	bool operator== (const CUInt128 &value) const {return (compareTo(value) == 0);}
	bool operator!= (const CUInt128 &value) const {return (compareTo(value) != 0);}

	void operator+  (ULONG value) {add(value);}
	void operator-  (ULONG value) {subtract(value);}
	void operator=  (ULONG value) {setValue(value);}
	bool operator<  (ULONG value) const {return (compareTo(value) <  0);}
	bool operator>  (ULONG value) const {return (compareTo(value) >  0);}
	bool operator<= (ULONG value) const {return (compareTo(value) <= 0);}
	bool operator>= (ULONG value) const {return (compareTo(value) >= 0);}
	bool operator== (ULONG value) const {return (compareTo(value) == 0);}
	bool operator!= (ULONG value) const {return (compareTo(value) != 0);}

private:

	ULONG m_data[4];
};

};

#endif 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -