资源简介
CBinary类,处理二进制与字符串之间的转换
代码片段和文件信息
/************************************************************************/
/* Binary.cpp: CBinary类实现文件 */
/************************************************************************/
#include “StdAfx.h“
#include “Binary.h“
CBinary::CBinary(void)
{
m_vctData.empty();
}
CBinary::CBinary(const unsigned char ch)
{
m_vctData.empty();
unsigned char ut;
ut = ch;
m_vctData.push_back(ut);
}
CBinary::~CBinary(void)
{
//对类中new 出来的空间进行释放
for (int i = 0; i < m_pchar.size(); i++)
{
char * p = m_pchar[i];
if (p != NULL)
{
delete [] p;
p = NULL;
}
}
for (int i = 0; i < m_pUchar.size(); i++)
{
unsigned char * p = m_pUchar[i];
if (p != NULL)
{
delete [] p;
p = NULL;
}
}
}
//////////////////////////////////////////////////////////////////////////
// example: pch = “1234“ --> m_vctData[] = {0x12 0x34}
//////////////////////////////////////////////////////////////////////////
CBinary::CBinary(const char* pch)
{
int len = strlen(pch);
for (int i = 0; i < len ; i+=2)
{
unsigned char bTemp;
bTemp = ((pch[i] - 0x30)<<0x04) + (pch[i+1] - 0x30);
m_vctData.push_back(bTemp);
}
}
CBinary::CBinary(const CBinary& bin)
{
for (int i = 0; i < bin.GetLength(); i++)
{
unsigned int bt;
bt = bin.GetAt(i);
m_vctData.push_back(bt);
}
}
CBinary& CBinary::operator =(char* pch)
{
int len = strlen(pch);
for (int i = 0; i < len ; i+=2)
{
unsigned char bTemp;
bTemp = ((pch[i] - 0x30)<<0x04) + (pch[i+1] - 0x30);
m_vctData.push_back(bTemp);
}
return (*this);
}
CBinary& CBinary::operator =(CBinary bin)
{
m_vctData.empty();
for (int i = 0; i < bin.GetLength(); i++)
{
unsigned int bt;
bt = bin.GetAt(i);
m_vctData.push_back(bt);
}
return (*this);
}
CBinary& CBinary::operator +=(CBinary bin)
{
for (int i = 0; i < bin.GetLength(); i++)
{
unsigned int bt;
bt = bin.GetAt(i);
m_vctData.push_back(bt);
}
return (*this);
}
CBinary& CBinary::operator +=(unsigned char uch)
{
m_vctData.push_back(uch);
return (*this);
}
CBinary& CBinary::operator +=(char* pch)
{
CBinary bin(pch);
for (int i = 0; i < bin.GetLength(); i++)
{
unsigned int bt;
bt = bin.GetAt(i);
m_vctData.push_back(bt);
}
return (*this);
}
int CBinary::GetLength() const
{
return m_vctData.size();
}
bool CBinary::isEmpty()
{
if (m_vctData.size())
{
return false;
}
else
{
return true;
}
}
unsigned char CBinary::GetAt(int nIndex) const
{
if (nIndex < m_vctData.size())
{
return m_vctData[nIndex];
}
else
{
return 0xFFFF;
}
}
void CBinary::SetAt(int nIndex unsigned char bValue)
{
m_vctData[nIndex] = bValue;
}
unsigned char CBinary::operator []( int nIndex ) const
{
if (nIndex < m_vctData.size())
{
return m_vctData[nIndex];
}
else
{
return 0xFFFF;
}
}
CBinary& operator +(const CBinary& bin
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6157 2010-08-16 14:41 CBinary\Binary.cpp
文件 3220 2010-08-16 14:40 CBinary\Binary.h
目录 0 2010-08-17 11:23 CBinary
----------- --------- ---------- ----- ----
9377 3
- 上一篇:通信原理课程公式 好东西
- 下一篇:artery使用手册
评论
共有 条评论