123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- #ifndef __CALUCONVERT_BY_ZEROT_
- #define __CALUCONVERT_BY_ZEROT_
- #pragma once
- #include <math.h>
- #include <bitset>
- #include <string>
- using std::bitset;
- using std::string;
- /************************************************************************
- 数据转换的种类;(后期完善,遇到再写,同时,这里的bit是从0开始索引的,低位在右,高位在左)
- 1 ̄1个字节的情况:
- ①RealBit:转为8位2进制位,求实位值(eg:0101 1110,取bit1~bit4的值 -> 0001 1110 = (10进制)30);
- ②VirtBit:转为8位2进制位,求虚位值(eg:0101 1110,取bit1~bit4的值 -> 1111 = (10进制)15);
- ③Literal:作为16进制ASCII码值,转对应的字符,即字节字面值(eg:0x30 -> '0'字符);
- ④???????:将ASCII码 实显 成字符(eg:0x30 -> "30"),即1个字节分解成 高4位和低4位2字节(eg: 0x30 -> 0x33,0x30),求10进制值;
- ⑤Decimal:直接将ASCII码值,换算成10进制(eg:0x30 -> 48);
- ⑥Literal_Decimal:作为16进制ASCII码值,转对应的字符的10进制数,(eg:0x31 -> '1'字符 -> (10进制)1);
- ⑦⑧⑨⑩
- 1 ̄2个字节的情况;
- ①作为1个<字节>的高4位,低4位的ASCII码对应字符,转为1个字节后,转为1 ̄1个字节处理情况(eg:0x34 0x42 -> 0x4B);
-
- 作为1个<字>的高字节,低字节(eg:0x34 0x42 -> 0x3442);
- ②将字转为16位2进制位,求实位值(eg:0010 0011 0101 1110,取bit9~bit15的值 -> 0010 0010 0000 0000 = (10进制)8704);
- ③将字转为16位2进制位,求虚位值(eg:0010 0011 0101 1110,取bit9~bit15的值 -> 10 001 = (10进制)17);
- ④将字ASCII码值,换算成10进制(eg:0x34 0x42 -> 0x3442 -> 13378);
- ⑤作为16进制ASCII码值,转对应的字符,即字节字面值(eg:0x34 0x42 -> "4B");
- ⑥MSB,求2字节中的高字节;
- ⑦LSB,求2字节中的低字节;
- ⑧⑨⑩
- 1 ̄3个字节的情况;
- ①3字节字面值(eg:0x32 0x31 0x30->"210");
- ②3个字节,顺序组合,求实位值(eg:0x32 0x31 0x30-> 0x323130 ->.....);
- ③3个字节,顺序组合,求虚位值(eg:0x32 0x31 0x30-> 0x323130 ->.....);
- ④
- ⑤⑥⑦⑧⑨⑩
- 1 ̄4个字节的情况;
- ①4字节字面值(eg: 0x33 0x33 0x31 0x30->"3310");
- ②4个字节按浮点数IEEE-754转成浮点数(eg:0x41 0xB2 0xCC 0xCD ->22.35);
- 两两字节一组,作为双字的高低字(eg:0xE4 0x67 0x00 0x00,-> H(0x00 0x00),L(0xE4 0x67) -> 双字(0x0000 0xE467));
- ③直接求双字的10进制值(eg:0x0000E467 -> 58471);
- ④将双字转32位2进制位,求实位值(eg:0x0000E467,... 1110 0100 0110 0111取bit3~bit6的值 -> ... 0000 0000 0110 0000 = (10进制)96);
- ⑤将双字转32位2进制位,求虚位值(eg:0x0000E467,... 1110 0100 0110 0111取bit3~bit6的值 -> 1100 = (10进制)12);
- ⑥⑦⑧⑨⑩
- 1 ̄5个字节的情况;
- ①5字节字面值(eg: 0x33 0x33 0x31 0x2E 0x30->"331.0");
- ②③④⑤⑥⑦⑧⑨⑩
- 1 ̄6个字节的情况;
- ①6字节字面值(eg: 0x33 0x33 0x31 0x2E 0x30 0x31->"331.01");
- ②③④⑤⑥⑦⑧⑨⑩
- 1 ̄7个字节的情况;
- ①7字节字面值(eg:0x34 0x33 0x33 0x31 0x2E 0x30 0x31->"4331.01");
- ②③④⑤⑥⑦⑧⑨⑩
- 1 ̄8个字节的情况;
- ①8字节字面值(eg:0x39 0x34 0x33 0x33 0x31 0x2E 0x30 0x31->"94331.01");
- ②直接8字节组,转64位2进制位,求实位值(eg:0x00000000E467,... 1110 0100 0110 0111取bit3~bit6的值 -> ... 0000 0000 0110 0000 = (10进制)96);
- ③直接8字节组,转64位2进制位,求虚位值(eg:0x00000000E467,... 1110 0100 0110 0111取bit3~bit6的值 ->1100 = (10进制)12);
- 每2个字节,作为1个新<字节>的高4位,低4位的ASCII码对应字符,组成新4字节;
- (eg:0x34 0x31 0x42 0x32 0x43 0x43 0x43 0x44->0x41 0xB2 0xCC 0xCD);
- ④1 ̄4个字节的情况;//与将新4字节浮点数IEEE-754转成浮点数(eg:0x41 0xB2 0xCC 0xCD ->22.35);
- ⑤⑥⑦⑧⑨⑩
- ************************************************************************/
- // 数据截取的长度;
- // 声明变量,要简单易看;
- enum CONVERT_LEN
- {
- BYTE_1 = 1,
- BYTE_2 ,
- BYTE_3 ,
- BYTE_4 ,
- BYTE_5 ,
- BYTE_6 ,
- BYTE_7 ,
- BYTE_8 ,
- };
- // 截取长度对应的数据转换类型;
- enum CONVERT_TYPE
- {
- BYTE_1_RealBit = 11001, // 实位值;
- BYTE_1_VirtBit = 11002, // 虚位值;
- BYTE_1_Literal = 11003, // 字面值;
- BYTE_1_Decimal = 11004, // 十进制;
- BYTE_1_Literal_Decimal = 11005, // 字面值的10进数;
- BYTE_1_2ASCII_Decimal = 11006, // 分解成2ASCII字节,求十进制值;
- /*预留12000~19000*/
- BYTE_2_RealBit = 21001, // 实位值;
- BYTE_2_VirtBit = 21002, // 虚位值;
- BYTE_2_Literal = 21003, // 字面值;
- BYTE_2_Decimal = 21004, // 十进制;
- BYTE_2_Literal_Decimal = 21005, // 字面值的10进数;
- BYTE_2_MSByte = 21006, // MSB高字节;
- BYTE_2_LSByte = 21007, // LSB低字节;
- // 化为1 ̄1个字节的情况:
- BYTE_2_1_RealBit = 22001,
- BYTE_2_1_VirtBit = 22002,
- BYTE_2_1_Literal = 22003,
- BYTE_2_1_Decimal = 22004,
- BYTE_2_1_Literal_Decimal= 22005,
- BYTE_2_1_2ASCII_Decimal = 22006,
- /*预留至29000*/
- BYTE_3_RealBit = 31001, // 实位值;
- BYTE_3_VirtBit = 31002, // 虚位值;
- BYTE_3_Literal = 31003, // 字面值;
- BYTE_3_Decimal = 31004, // 十进制;
- BYTE_3_Literal_Decimal = 31005, // 字面值的10进数;
- /*预留至39000*/
- BYTE_4_RealBit = 41001, // 实位值;
- BYTE_4_VirtBit = 41002, // 虚位值;
- BYTE_4_Literal = 41003, // 字面值;
- BYTE_4_Decimal = 41004, // 十进制;
- BYTE_4_Literal_Decimal = 41005, // 字面值的10进数;
- BYTE_4_Float = 41006, // 浮点数;
- /*预留至49000*/
- BYTE_5_RealBit = 51001, // 实位值;
- BYTE_5_VirtBit = 51002, // 虚位值;
- BYTE_5_Literal = 51003, // 字面值;
- BYTE_5_Decimal = 51004, // 十进制;
- BYTE_5_Literal_Decimal = 51005, // 字面值的10进数;
- /*预留至59000*/
- BYTE_6_RealBit = 61001, // 实位值;
- BYTE_6_VirtBit = 61002, // 虚位值;
- BYTE_6_Literal = 61003, // 字面值;
- BYTE_6_Decimal = 61004, // 十进制;
- BYTE_6_Literal_Decimal = 61005, // 字面值的10进数;
- /*预留至69000*/
- BYTE_7_RealBit = 71001, // 实位值;
- BYTE_7_VirtBit = 71002, // 虚位值;
- BYTE_7_Literal = 71003, // 字面值;
- BYTE_7_Decimal = 71004, // 十进制;
- BYTE_7_Literal_Decimal = 71005, // 字面值的10进数;
- /*预留至79000*/
- BYTE_8_RealBit = 81001, // 实位值;
- BYTE_8_VirtBit = 81002, // 虚位值;
- BYTE_8_Literal = 81003, // 字面值;
- BYTE_8_Decimal = 81004, // 十进制;
- BYTE_8_Literal_Decimal = 81005, // 字面值的10进数;
- BYTE_8_4_Float = 81006, // 浮点数;
- /*预留至89000*/
- };
- // 先不做模板函数;
- class CCaluConvert
- {
- public:
- CCaluConvert(void);
- virtual ~CCaluConvert(void);
- // * 转换函数(唯一接口);
- // * szDestValue: 目标字符;
- // * szSourceValue: 源字符;
- // * DestLen: 目标字符传递的长度;
- // * SourceLen: 源字符传递的长度(暂时没用,做扩展预留,升级使用);
- // * iIndex: 源字符位置索引;
- // * iCutLen: 源字符截取长度;
- // * iSBit: 目标字符2进制,起始位;
- // * iEBit: 目标字符2进制,终止位;
- // * dConfs: 目标字符转换系数;
- // * dCrrect: 目标字符校正值;
- // * dwCaluType: 目标字符转换类型;
- // 当前使用该形式函数,数组大小也可以是任意的,比使用引用数组方便;
- void CONVERTS(
- char *szDestValue,
- const int &DestLen,
- const BYTE *szSourceValue,
- const int &SourceLen,
- const int &iIndex,
- const int &iCutLen,
- const int &iSBit,
- const int &iEBit,
- const double &dConfs,
- const double &dCrrect,
- const DWORD &dwCaluType);
- protected:
- // * szValue: 目标字符;
- // * VLen: 目标字符长度(暂时无用);
- // * szSource: 源字符;
- // * iSBit: 目标字符2进制,起始位;
- // * iEBit: 目标字符2进制,终止位;
- // * dConfs: 目标字符转换系数;
- // * dCrrect: 目标字符校正值;
- // * dwCaluType: 目标字符转换类型;
- void _CONVERTORDER_1BYTE(
- char *&szValue,
- const int &VLen,
- BYTE *&szSource,
- const int &iSBit,
- const int &iEBit,
- const double &dConfs,
- const double &dCorrect,
- const DWORD &dwCaluType);
- void _CONVERTORDER_2BYTE(
- char *&szValue,
- const int &VLen,
- BYTE *&szSource,
- const int &iSBit,
- const int &iEBit,
- const double &dConfs,
- const double &dCorrect,
- const DWORD &dwCaluType);
- void _CONVERTORDER_3BYTE(
- char *&szValue,
- const int &VLen,
- BYTE *&szSource,
- const int &iSBit,
- const int &iEBit,
- const double &dConfs,
- const double &dCorrect,
- const DWORD &dwCaluType);
- void _CONVERTORDER_4BYTE(
- char *&szValue,
- const int &VLen,
- BYTE *&szSource,
- const int &iSBit,
- const int &iEBit,
- const double &dConfs,
- const double &dCorrect,
- const DWORD &dwCaluType);
- void _CONVERTORDER_5BYTE(
- char *&szValue,
- const int &VLen,
- BYTE *&szSource,
- const int &iSBit,
- const int &iEBit,
- const double &dConfs,
- const double &dCorrect,
- const DWORD &dwCaluType);
- void _CONVERTORDER_6BYTE(
- char *&szValue,
- const int &VLen,
- BYTE *&szSource,
- const int &iSBit,
- const int &iEBit,
- const double &dConfs,
- const double &dCorrect,
- const DWORD &dwCaluType);
- void _CONVERTORDER_7BYTE(
- char *&szValue,
- const int &VLen,
- BYTE *&szSource,
- const int &iSBit,
- const int &iEBit,
- const double &dConfs,
- const double &dCorrect,
- const DWORD &dwCaluType);
- void _CONVERTORDER_8BYTE(
- char *&szValue,
- const int &VLen,
- BYTE *&szSource,
- const int &iSBit,
- const int &iEBit,
- const double &dConfs,
- const double &dCorrect,
- const DWORD &dwCaluType);
-
- private:
- public:
- // 通用函数;
- inline void ReturnCorrectValue(char *szValue,const int &VLen,const double &dConfs,const double &dCrrect);
- inline void Literal(char *szValue,BYTE *szSource, const int &SLen);
- inline void Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &SLen, const int &iSBit, const int &iEBit);
- void VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &SLen, const int &iSBit, const int &iEBit);
- // 以下,大部分位函数没用到,暂时不做;
- // 1字节;
- void _BYTE_1_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_1_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_1_Literal(char *szValue, const int &VLen, BYTE *szSource);
- void _BYTE_1_Decimal(char *szValue, const int &VLen,BYTE *szSource, const double &dConfs);
- void _BYTE_1_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- // 2字节;
- void _BYTE_2_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_2_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_2_Literal(char *szValue, const int &VLen, BYTE *szSource);
- void _BYTE_2_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void _BYTE_2_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- // 默认取高低字节的十进制数;
- void _BYTE_2_MSByte(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void _BYTE_2_LSByte(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void _BYTE_2_1_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_2_1_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_2_1_Literal(char *szValue, const int &VLen, BYTE *szSource);
- void _BYTE_2_1_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void _BYTE_2_1_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- // 3字节;
- void _BYTE_3_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_3_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_3_Literal(char *szValue, const int &VLen, BYTE *szSource);
- void _BYTE_3_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void _BYTE_3_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- // 4字节;
- void _BYTE_4_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_4_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_4_Literal(char *szValue, const int &VLen, BYTE *szSource);
- void _BYTE_4_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void _BYTE_4_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void _BYTE_4_Float(char *szValue, const int &VLen, BYTE *szSource);
- // 5字节;
- void _BYTE_5_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_5_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_5_Literal(char *szValue, const int &VLen, BYTE *szSource);
- void _BYTE_5_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void _BYTE_5_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- // 6字节;
- void _BYTE_6_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_6_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_6_Literal(char *szValue, const int &VLen, BYTE *szSource);
- void _BYTE_6_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void _BYTE_6_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- // 7字节;
- void _BYTE_7_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_7_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_7_Literal(char *szValue, const int &VLen, BYTE *szSource);
- void _BYTE_7_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void _BYTE_7_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- // 8字节;
- void _BYTE_8_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_8_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
- void _BYTE_8_Literal(char *szValue, const int &VLen, BYTE *szSource);
- void _BYTE_8_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void _BYTE_8_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
- void _BYTE_8_4_Float(char *szValue, const int &VLen, BYTE *szSource);
- private:
- public:
- inline char TwoHexCharToChar(char ch1,char ch2);
- // 十六进制ASCII字符转对应整数(eg:0x42 ->'B' ->11);
- inline INT ASCII_to_Byte(char c);
- //1 ̄2个字节的情况:①两字节当做高4位,低4位,组成1新字节;
- BYTE ReturnASCIIByte(BYTE hBy,BYTE lBy);
- BYTE ReturnASCIIByte(BYTE *bySource);
- BYTE ReturnASCIIByte(BYTE *bySource,const int &iIndex);
- //1 ̄2个字节的情况:②两字节当做高字节,低字节,组合1个字;
- inline WORD ReturnASCIIWORD(BYTE hBy,BYTE lBy);
- inline WORD ReturnASCIIWORD(BYTE *bySource);
- inline WORD ReturnASCIIWORD(BYTE *bySource,const int &iIndex);
- inline DWORD ReturnASCIIDWORD(WORD hWd,WORD lWd);
- DWORD ReturnASCIIDWORD(BYTE *bySource);
- DWORD ReturnASCIIDWORD(BYTE *bySource,const int &iIndex);
- void ReturnFloat_8Byte(char *szValue, const int &VLen, BYTE *szSource);
- void ReturnBinaryString(char (&szValue)[9],BYTE bySource); // 正向;
- void ReturnBinaryReverseString(char (&szValue)[9],BYTE bySource); // 反向;
- string ReturnBinaryString(BYTE bySource); // 正向;
- string ReturnBinaryReverseString(BYTE bySource); // 反向;
- template <int nCount>
- void GetRealBitValue(char *szValue, const int &VLen,string &strBinary,const int &iSBit, const int &iEBit);
- template <int nCount>
- void GetVirtBitValue(char *szValue, const int &VLen,string &strBinary,const int &iSBit, const int &iEBit);
- private:
- //char m_szReturn[1024];
- public:
- // 字符大小写互换;
- void swapUpperLower(char *szMsg);
- // 字符全转为大写;
- void upperAllByte(char *szMsg);
- // 字符全转为小写;
- void lowerAllByte(char *szMsg);
- // 一串字符的每个字转换为两个16进制字节表示;
- void ByteToTwoByte( char *szMsg, char *szConvMsg );
- // 一串字符的每两个字节转换为一个字;
- void TwoByteToByte(char *szMsg, char *szConvMsg );
- // 十六进制Ascii字符转整数;
- //INT AsciiToBYTE(char szMsg);
- // 字符转ASCII;
- char ByteToAscii(BYTE btSrc);
- char lowercase2uppercase(BYTE btSrc);
- // 由数据精度获得浮点数的字符串值;
- CString GetDoubleText(double d);
- int DigitToBinary(WORD wdSource, char* pDes, int iBit) ;
- // 该函数把四位二进制转换成十六进制数;
- char Hex16(char WillChangeNum[]);
- // 将一串字符字母小写转大写;
- void strReverse( char *str );
- char twoHexByte2Word(char Hbyte,char Lbyte) ;
- void Str2HexStr(char *szHexString,char *szString,int *iHexStringLen);
- };
- void CCaluConvert::ReturnCorrectValue(char *szValue,const int &VLen,const double &dConfs,const double &dCrrect)
- {
- if ( dCrrect == 0.0 && dConfs == 0.0)
- return;
- double dValue = atof(szValue);
- if (dConfs == 0.0)
- {
- dValue += dCrrect;//校正处理;
- sprintf_s(szValue,VLen,"%f",dValue);
- return;
- }
- if ( dCrrect == 0.0)
- {
- dValue *= dConfs;
- sprintf_s(szValue,VLen,"%f",dValue);
- return;
- }
- dValue *= dConfs;
- dValue += dCrrect;
- sprintf_s(szValue,VLen,"%f",dValue);
-
- }
- INT CCaluConvert::ASCII_to_Byte(char c)
- {
- int iConvt = static_cast<int>(c);
- if ((c >= 'A')&&(c <= 'F'))
- iConvt = iConvt - 'A' + 10;
- else if ((c >= 'a')&&(c <= 'f'))
- iConvt = iConvt - 'a' + 10;
- else if ((c >= '0')&&(c <= '9'))
- iConvt -= '0';
- return iConvt;
- }
- // WORD
- WORD CCaluConvert::ReturnASCIIWORD(BYTE hBy,BYTE lBy)
- {
- // Z.t注意,hBy左移8位,会因为左边等式的类型而隐式转换成左边等式的类型;
- // 示例:hBy = 0x42,lBy = 0x31;
- // BYTE bValue = hBy << 8 | lBy;
- // 最后:bValue = 0x31;
- WORD wValue = hBy << 8 | lBy;
- return wValue;
- }
- WORD CCaluConvert::ReturnASCIIWORD(BYTE *bySource)
- {
- WORD wValue;
- wValue = bySource[0] << 8 | bySource[1] ;
- return wValue;
- }
- WORD CCaluConvert::ReturnASCIIWORD(BYTE *bySource,const int &iIndex)
- {
- WORD wValue;
- wValue = bySource[iIndex] << 8 | bySource[iIndex+1] ;
- return wValue;
- }
- // DWORD
- DWORD CCaluConvert::ReturnASCIIDWORD(WORD hWd,WORD lWd)
- {
- DWORD dwValue;
- dwValue = hWd << 16 | lWd;
- return dwValue;
- }
- void CCaluConvert::Literal(char *szValue,BYTE *szSource, const int &SLen)
- {
- memcpy(szValue,szSource,SLen);
- }
- void CCaluConvert::Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- double dRet = atof((char*)szSource);
- sprintf_s(szValue,VLen,"%f",dRet);
- }
- char CCaluConvert::TwoHexCharToChar(char ch1,char ch2)
- {
- char Numb1;
- char Numb2;
- if (ch1 >= 'A')
- Numb1 = (toupper(ch1)-'0'-7)*16;
- else
- Numb1 = (ch1 - '0')*16;
- if (ch2 >= 'A')
- Numb2 = (toupper(ch2) - '0' - 7);
- else
- Numb2 = (ch2 - '0');
- return (Numb1 + Numb2);
- }
- #endif
|