All pastes #718807 Raw Edit

Unbenannt

public cpp v1 · immutable
#718807 ·published 2007-09-28 18:25 UTC
rendered paste body
template<class TYPE>bool *NumberToBin(TYPE Number){	unsigned int BitSize = 8 * sizeof(TYPE) - 2;	bool *Bin = new bool[BitSize];	unsigned char Counter = 0;	for (int i=BitSize;i>-1;i--)	{		Bin[Counter] = IS_BIT_SET(Number, i) ? 1 : 0;		++Counter;	}	return Bin;}template<class TYPE>TYPE BinToNumber(bool *Bin, bool Delete = false){	unsigned char TypeLen = 8 * sizeof(TYPE) - 2;	TYPE RetVal = 0;	for (char c=TypeLen;c>-1;c--)	{		if (Bin[c])			BIT_SET(RetVal, TypeLen-c);		else			BIT_CLEAR(RetVal, TypeLen-c);	}	if (Delete)		delete[] Bin;	return RetVal;}#define PACKET_MAX_LEN 65536	char m_Data[PACKET_MAX_LEN]; // 0 - 65535	unsigned int m_Pos;	unsigned int m_Length;	void BitModi(int i, int j, bool *Bin)	{		unsigned char Counter = 0;		for (;i<j;i++)		{			if (Bin[i])				BIT_SET(m_Data[m_Pos], Counter);			else				BIT_CLEAR(m_Data[m_Pos], Counter);			++Counter;		}	}	void w32(int Data)	{		Shared::GetLogStream() << "SendPacket::w32():" << std::endl;		bool *Bin = NumberToBin<int>(Data);		BitModi(0, 8, Bin);		DumpCur();		++m_Pos;		BitModi(8, 16, Bin);		DumpCur();		++m_Pos;		BitModi(16, 24, Bin);		DumpCur();		++m_Pos;		BitModi(24, 31, Bin);		DumpCur();		++m_Pos;		m_Length = m_Pos;	}