eis/inc/base/BitTool.h

105 lines
3.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*********************************************************************
*
* 文 件: BitTool.h 提供对二进制相关的一些处理功能的接口定义
*
* 版权所有: Shanghai Baosight Software Co., Ltd.
*
* 概述 :将一个十进制数,转换成一个二进制的字符串
* 获取一个十进制数在使用二进制表示时含有1的个数
*
*
* 版本历史
* 1.0 2010-06-17 echo_li 初次建立,增加注释
*
*********************************************************************/
#ifndef _BITTOOL_H
#define _BITTOOL_H
#include <string.h>
#include <string>
#include <iostream>
using namespace std;
namespace baosight
{
/*********************************************************************
* 类 名: BitTool
* 版权所有: Shanghai Baosight Software Co., Ltd.
* 类 职 责:提供二进制相关处理,包括将十进制转换成二进制,二进制转换成十进制等
* //TODO
* //TODO
* 版本历史
* 1.0 2010-06-17 echo_li 由冷轧连退项目获取
*
*********************************************************************/
class BitTool
{
public:
/**********************************************************************
* 概述: 数据转变为二进制字符串,如 5 变为 00000101
* 函数名: Dec2BinnaryString
* 返回值: std::string
* 参数列表: 参数类型 取值范围 描述
* num: unsigned int 数值
* byteNum: int 位数
*
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
*
**********************************************************************/
static string Dec2BinnaryString(unsigned int num,int byteNum = 1 );
/**********************************************************************
* 概述: num用二进制表示的时候共有多少个1
* 函数名: Num1InDec
* 返回值: int
* 参数列表: 参数类型 取值范围 描述
* num: unsigned int
*
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
*
**********************************************************************/
static int Num1InDec(unsigned int num);
/**********************************************************************
* 概述: 二进制数组变成long如 [0]=1,[1]=0,[2]=1--->101-->5
* 函数名: BitArray2Long
* 返回值: long
* 参数列表: 参数类型 取值范围 描述
* iPosO: short *
* bitLen: int
* direction: int
*
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
*
**********************************************************************/
static long BitArray2Long(short* iPosO,int bitLen = 8, int direction = 0);
/**********************************************************************
* 概述: long变成二进制数组
* 函数名: Long2BitArray
* 返回值: int
* 参数列表: 参数类型 取值范围 描述
* num: const unsigned long
* pBitArray: short *
* length: int
*
* 版本历史
* 1.0 2010-09-02 echo_li 增加注释
*
**********************************************************************/
static int Long2BitArray(const unsigned long num,short* pBitArray , int length);
static string Byte2Bits(const char byte);
private:
static const int CN_ONEBYTE_BITS = 8;
};
}
#endif