CaluConvert.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. #ifndef __CALUCONVERT_BY_ZEROT_
  2. #define __CALUCONVERT_BY_ZEROT_
  3. #pragma once
  4. #include <math.h>
  5. #include <bitset>
  6. #include <string>
  7. using std::bitset;
  8. using std::string;
  9. /************************************************************************
  10. 数据转换的种类;(后期完善,遇到再写,同时,这里的bit是从0开始索引的,低位在右,高位在左)
  11. 1 ̄1个字节的情况:
  12. ①RealBit:转为8位2进制位,求实位值(eg:0101 1110,取bit1~bit4的值 -> 0001 1110 = (10进制)30);
  13. ②VirtBit:转为8位2进制位,求虚位值(eg:0101 1110,取bit1~bit4的值 -> 1111 = (10进制)15);
  14. ③Literal:作为16进制ASCII码值,转对应的字符,即字节字面值(eg:0x30 -> '0'字符);
  15. ④???????:将ASCII码 实显 成字符(eg:0x30 -> "30"),即1个字节分解成 高4位和低4位2字节(eg: 0x30 -> 0x33,0x30),求10进制值;
  16. ⑤Decimal:直接将ASCII码值,换算成10进制(eg:0x30 -> 48);
  17. ⑥Literal_Decimal:作为16进制ASCII码值,转对应的字符的10进制数,(eg:0x31 -> '1'字符 -> (10进制)1);
  18. ⑦⑧⑨⑩
  19. 1 ̄2个字节的情况;
  20. ①作为1个<字节>的高4位,低4位的ASCII码对应字符,转为1个字节后,转为1 ̄1个字节处理情况(eg:0x34 0x42 -> 0x4B);
  21. 作为1个<字>的高字节,低字节(eg:0x34 0x42 -> 0x3442);
  22. ②将字转为16位2进制位,求实位值(eg:0010 0011 0101 1110,取bit9~bit15的值 -> 0010 0010 0000 0000 = (10进制)8704);
  23. ③将字转为16位2进制位,求虚位值(eg:0010 0011 0101 1110,取bit9~bit15的值 -> 10 001 = (10进制)17);
  24. ④将字ASCII码值,换算成10进制(eg:0x34 0x42 -> 0x3442 -> 13378);
  25. ⑤作为16进制ASCII码值,转对应的字符,即字节字面值(eg:0x34 0x42 -> "4B");
  26. ⑥MSB,求2字节中的高字节;
  27. ⑦LSB,求2字节中的低字节;
  28. ⑧⑨⑩
  29. 1 ̄3个字节的情况;
  30. ①3字节字面值(eg:0x32 0x31 0x30->"210");
  31. ②3个字节,顺序组合,求实位值(eg:0x32 0x31 0x30-> 0x323130 ->.....);
  32. ③3个字节,顺序组合,求虚位值(eg:0x32 0x31 0x30-> 0x323130 ->.....);
  33. ⑤⑥⑦⑧⑨⑩
  34. 1 ̄4个字节的情况;
  35. ①4字节字面值(eg: 0x33 0x33 0x31 0x30->"3310");
  36. ②4个字节按浮点数IEEE-754转成浮点数(eg:0x41 0xB2 0xCC 0xCD ->22.35);
  37. 两两字节一组,作为双字的高低字(eg:0xE4 0x67 0x00 0x00,-> H(0x00 0x00),L(0xE4 0x67) -> 双字(0x0000 0xE467));
  38. ③直接求双字的10进制值(eg:0x0000E467 -> 58471);
  39. ④将双字转32位2进制位,求实位值(eg:0x0000E467,... 1110 0100 0110 0111取bit3~bit6的值 -> ... 0000 0000 0110 0000 = (10进制)96);
  40. ⑤将双字转32位2进制位,求虚位值(eg:0x0000E467,... 1110 0100 0110 0111取bit3~bit6的值 -> 1100 = (10进制)12);
  41. ⑥⑦⑧⑨⑩
  42. 1 ̄5个字节的情况;
  43. ①5字节字面值(eg: 0x33 0x33 0x31 0x2E 0x30->"331.0");
  44. ②③④⑤⑥⑦⑧⑨⑩
  45. 1 ̄6个字节的情况;
  46. ①6字节字面值(eg: 0x33 0x33 0x31 0x2E 0x30 0x31->"331.01");
  47. ②③④⑤⑥⑦⑧⑨⑩
  48. 1 ̄7个字节的情况;
  49. ①7字节字面值(eg:0x34 0x33 0x33 0x31 0x2E 0x30 0x31->"4331.01");
  50. ②③④⑤⑥⑦⑧⑨⑩
  51. 1 ̄8个字节的情况;
  52. ①8字节字面值(eg:0x39 0x34 0x33 0x33 0x31 0x2E 0x30 0x31->"94331.01");
  53. ②直接8字节组,转64位2进制位,求实位值(eg:0x00000000E467,... 1110 0100 0110 0111取bit3~bit6的值 -> ... 0000 0000 0110 0000 = (10进制)96);
  54. ③直接8字节组,转64位2进制位,求虚位值(eg:0x00000000E467,... 1110 0100 0110 0111取bit3~bit6的值 ->1100 = (10进制)12);
  55. 每2个字节,作为1个新<字节>的高4位,低4位的ASCII码对应字符,组成新4字节;
  56. (eg:0x34 0x31 0x42 0x32 0x43 0x43 0x43 0x44->0x41 0xB2 0xCC 0xCD);
  57. ④1 ̄4个字节的情况;//与将新4字节浮点数IEEE-754转成浮点数(eg:0x41 0xB2 0xCC 0xCD ->22.35);
  58. ⑤⑥⑦⑧⑨⑩
  59. ************************************************************************/
  60. // 数据截取的长度;
  61. // 声明变量,要简单易看;
  62. enum CONVERT_LEN
  63. {
  64. BYTE_1 = 1,
  65. BYTE_2 ,
  66. BYTE_3 ,
  67. BYTE_4 ,
  68. BYTE_5 ,
  69. BYTE_6 ,
  70. BYTE_7 ,
  71. BYTE_8 ,
  72. };
  73. // 截取长度对应的数据转换类型;
  74. enum CONVERT_TYPE
  75. {
  76. BYTE_1_RealBit = 11001, // 实位值;
  77. BYTE_1_VirtBit = 11002, // 虚位值;
  78. BYTE_1_Literal = 11003, // 字面值;
  79. BYTE_1_Decimal = 11004, // 十进制;
  80. BYTE_1_Literal_Decimal = 11005, // 字面值的10进数;
  81. BYTE_1_2ASCII_Decimal = 11006, // 分解成2ASCII字节,求十进制值;
  82. /*预留12000~19000*/
  83. BYTE_2_RealBit = 21001, // 实位值;
  84. BYTE_2_VirtBit = 21002, // 虚位值;
  85. BYTE_2_Literal = 21003, // 字面值;
  86. BYTE_2_Decimal = 21004, // 十进制;
  87. BYTE_2_Literal_Decimal = 21005, // 字面值的10进数;
  88. BYTE_2_MSByte = 21006, // MSB高字节;
  89. BYTE_2_LSByte = 21007, // LSB低字节;
  90. // 化为1 ̄1个字节的情况:
  91. BYTE_2_1_RealBit = 22001,
  92. BYTE_2_1_VirtBit = 22002,
  93. BYTE_2_1_Literal = 22003,
  94. BYTE_2_1_Decimal = 22004,
  95. BYTE_2_1_Literal_Decimal= 22005,
  96. BYTE_2_1_2ASCII_Decimal = 22006,
  97. /*预留至29000*/
  98. BYTE_3_RealBit = 31001, // 实位值;
  99. BYTE_3_VirtBit = 31002, // 虚位值;
  100. BYTE_3_Literal = 31003, // 字面值;
  101. BYTE_3_Decimal = 31004, // 十进制;
  102. BYTE_3_Literal_Decimal = 31005, // 字面值的10进数;
  103. /*预留至39000*/
  104. BYTE_4_RealBit = 41001, // 实位值;
  105. BYTE_4_VirtBit = 41002, // 虚位值;
  106. BYTE_4_Literal = 41003, // 字面值;
  107. BYTE_4_Decimal = 41004, // 十进制;
  108. BYTE_4_Literal_Decimal = 41005, // 字面值的10进数;
  109. BYTE_4_Float = 41006, // 浮点数;
  110. /*预留至49000*/
  111. BYTE_5_RealBit = 51001, // 实位值;
  112. BYTE_5_VirtBit = 51002, // 虚位值;
  113. BYTE_5_Literal = 51003, // 字面值;
  114. BYTE_5_Decimal = 51004, // 十进制;
  115. BYTE_5_Literal_Decimal = 51005, // 字面值的10进数;
  116. /*预留至59000*/
  117. BYTE_6_RealBit = 61001, // 实位值;
  118. BYTE_6_VirtBit = 61002, // 虚位值;
  119. BYTE_6_Literal = 61003, // 字面值;
  120. BYTE_6_Decimal = 61004, // 十进制;
  121. BYTE_6_Literal_Decimal = 61005, // 字面值的10进数;
  122. /*预留至69000*/
  123. BYTE_7_RealBit = 71001, // 实位值;
  124. BYTE_7_VirtBit = 71002, // 虚位值;
  125. BYTE_7_Literal = 71003, // 字面值;
  126. BYTE_7_Decimal = 71004, // 十进制;
  127. BYTE_7_Literal_Decimal = 71005, // 字面值的10进数;
  128. /*预留至79000*/
  129. BYTE_8_RealBit = 81001, // 实位值;
  130. BYTE_8_VirtBit = 81002, // 虚位值;
  131. BYTE_8_Literal = 81003, // 字面值;
  132. BYTE_8_Decimal = 81004, // 十进制;
  133. BYTE_8_Literal_Decimal = 81005, // 字面值的10进数;
  134. BYTE_8_4_Float = 81006, // 浮点数;
  135. /*预留至89000*/
  136. };
  137. // 先不做模板函数;
  138. class CCaluConvert
  139. {
  140. public:
  141. CCaluConvert(void);
  142. virtual ~CCaluConvert(void);
  143. // * 转换函数(唯一接口);
  144. // * szDestValue: 目标字符;
  145. // * szSourceValue: 源字符;
  146. // * DestLen: 目标字符传递的长度;
  147. // * SourceLen: 源字符传递的长度(暂时没用,做扩展预留,升级使用);
  148. // * iIndex: 源字符位置索引;
  149. // * iCutLen: 源字符截取长度;
  150. // * iSBit: 目标字符2进制,起始位;
  151. // * iEBit: 目标字符2进制,终止位;
  152. // * dConfs: 目标字符转换系数;
  153. // * dCrrect: 目标字符校正值;
  154. // * dwCaluType: 目标字符转换类型;
  155. // 当前使用该形式函数,数组大小也可以是任意的,比使用引用数组方便;
  156. void CONVERTS(
  157. char *szDestValue,
  158. const int &DestLen,
  159. const BYTE *szSourceValue,
  160. const int &SourceLen,
  161. const int &iIndex,
  162. const int &iCutLen,
  163. const int &iSBit,
  164. const int &iEBit,
  165. const double &dConfs,
  166. const double &dCrrect,
  167. const DWORD &dwCaluType);
  168. protected:
  169. // * szValue: 目标字符;
  170. // * VLen: 目标字符长度(暂时无用);
  171. // * szSource: 源字符;
  172. // * iSBit: 目标字符2进制,起始位;
  173. // * iEBit: 目标字符2进制,终止位;
  174. // * dConfs: 目标字符转换系数;
  175. // * dCrrect: 目标字符校正值;
  176. // * dwCaluType: 目标字符转换类型;
  177. void _CONVERTORDER_1BYTE(
  178. char *&szValue,
  179. const int &VLen,
  180. BYTE *&szSource,
  181. const int &iSBit,
  182. const int &iEBit,
  183. const double &dConfs,
  184. const double &dCorrect,
  185. const DWORD &dwCaluType);
  186. void _CONVERTORDER_2BYTE(
  187. char *&szValue,
  188. const int &VLen,
  189. BYTE *&szSource,
  190. const int &iSBit,
  191. const int &iEBit,
  192. const double &dConfs,
  193. const double &dCorrect,
  194. const DWORD &dwCaluType);
  195. void _CONVERTORDER_3BYTE(
  196. char *&szValue,
  197. const int &VLen,
  198. BYTE *&szSource,
  199. const int &iSBit,
  200. const int &iEBit,
  201. const double &dConfs,
  202. const double &dCorrect,
  203. const DWORD &dwCaluType);
  204. void _CONVERTORDER_4BYTE(
  205. char *&szValue,
  206. const int &VLen,
  207. BYTE *&szSource,
  208. const int &iSBit,
  209. const int &iEBit,
  210. const double &dConfs,
  211. const double &dCorrect,
  212. const DWORD &dwCaluType);
  213. void _CONVERTORDER_5BYTE(
  214. char *&szValue,
  215. const int &VLen,
  216. BYTE *&szSource,
  217. const int &iSBit,
  218. const int &iEBit,
  219. const double &dConfs,
  220. const double &dCorrect,
  221. const DWORD &dwCaluType);
  222. void _CONVERTORDER_6BYTE(
  223. char *&szValue,
  224. const int &VLen,
  225. BYTE *&szSource,
  226. const int &iSBit,
  227. const int &iEBit,
  228. const double &dConfs,
  229. const double &dCorrect,
  230. const DWORD &dwCaluType);
  231. void _CONVERTORDER_7BYTE(
  232. char *&szValue,
  233. const int &VLen,
  234. BYTE *&szSource,
  235. const int &iSBit,
  236. const int &iEBit,
  237. const double &dConfs,
  238. const double &dCorrect,
  239. const DWORD &dwCaluType);
  240. void _CONVERTORDER_8BYTE(
  241. char *&szValue,
  242. const int &VLen,
  243. BYTE *&szSource,
  244. const int &iSBit,
  245. const int &iEBit,
  246. const double &dConfs,
  247. const double &dCorrect,
  248. const DWORD &dwCaluType);
  249. private:
  250. public:
  251. // 通用函数;
  252. inline void ReturnCorrectValue(char *szValue,const int &VLen,const double &dConfs,const double &dCrrect);
  253. inline void Literal(char *szValue,BYTE *szSource, const int &SLen);
  254. inline void Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  255. void RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &SLen, const int &iSBit, const int &iEBit);
  256. void VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &SLen, const int &iSBit, const int &iEBit);
  257. // 以下,大部分位函数没用到,暂时不做;
  258. // 1字节;
  259. void _BYTE_1_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  260. void _BYTE_1_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  261. void _BYTE_1_Literal(char *szValue, const int &VLen, BYTE *szSource);
  262. void _BYTE_1_Decimal(char *szValue, const int &VLen,BYTE *szSource, const double &dConfs);
  263. void _BYTE_1_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  264. // 2字节;
  265. void _BYTE_2_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  266. void _BYTE_2_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  267. void _BYTE_2_Literal(char *szValue, const int &VLen, BYTE *szSource);
  268. void _BYTE_2_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  269. void _BYTE_2_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  270. // 默认取高低字节的十进制数;
  271. void _BYTE_2_MSByte(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  272. void _BYTE_2_LSByte(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  273. void _BYTE_2_1_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  274. void _BYTE_2_1_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  275. void _BYTE_2_1_Literal(char *szValue, const int &VLen, BYTE *szSource);
  276. void _BYTE_2_1_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  277. void _BYTE_2_1_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  278. // 3字节;
  279. void _BYTE_3_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  280. void _BYTE_3_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  281. void _BYTE_3_Literal(char *szValue, const int &VLen, BYTE *szSource);
  282. void _BYTE_3_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  283. void _BYTE_3_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  284. // 4字节;
  285. void _BYTE_4_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  286. void _BYTE_4_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  287. void _BYTE_4_Literal(char *szValue, const int &VLen, BYTE *szSource);
  288. void _BYTE_4_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  289. void _BYTE_4_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  290. void _BYTE_4_Float(char *szValue, const int &VLen, BYTE *szSource);
  291. // 5字节;
  292. void _BYTE_5_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  293. void _BYTE_5_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  294. void _BYTE_5_Literal(char *szValue, const int &VLen, BYTE *szSource);
  295. void _BYTE_5_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  296. void _BYTE_5_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  297. // 6字节;
  298. void _BYTE_6_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  299. void _BYTE_6_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  300. void _BYTE_6_Literal(char *szValue, const int &VLen, BYTE *szSource);
  301. void _BYTE_6_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  302. void _BYTE_6_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  303. // 7字节;
  304. void _BYTE_7_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  305. void _BYTE_7_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  306. void _BYTE_7_Literal(char *szValue, const int &VLen, BYTE *szSource);
  307. void _BYTE_7_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  308. void _BYTE_7_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  309. // 8字节;
  310. void _BYTE_8_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  311. void _BYTE_8_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit);
  312. void _BYTE_8_Literal(char *szValue, const int &VLen, BYTE *szSource);
  313. void _BYTE_8_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  314. void _BYTE_8_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs);
  315. void _BYTE_8_4_Float(char *szValue, const int &VLen, BYTE *szSource);
  316. private:
  317. public:
  318. inline char TwoHexCharToChar(char ch1,char ch2);
  319. // 十六进制ASCII字符转对应整数(eg:0x42 ->'B' ->11);
  320. inline INT ASCII_to_Byte(char c);
  321. //1 ̄2个字节的情况:①两字节当做高4位,低4位,组成1新字节;
  322. BYTE ReturnASCIIByte(BYTE hBy,BYTE lBy);
  323. BYTE ReturnASCIIByte(BYTE *bySource);
  324. BYTE ReturnASCIIByte(BYTE *bySource,const int &iIndex);
  325. //1 ̄2个字节的情况:②两字节当做高字节,低字节,组合1个字;
  326. inline WORD ReturnASCIIWORD(BYTE hBy,BYTE lBy);
  327. inline WORD ReturnASCIIWORD(BYTE *bySource);
  328. inline WORD ReturnASCIIWORD(BYTE *bySource,const int &iIndex);
  329. inline DWORD ReturnASCIIDWORD(WORD hWd,WORD lWd);
  330. DWORD ReturnASCIIDWORD(BYTE *bySource);
  331. DWORD ReturnASCIIDWORD(BYTE *bySource,const int &iIndex);
  332. void ReturnFloat_8Byte(char *szValue, const int &VLen, BYTE *szSource);
  333. void ReturnBinaryString(char (&szValue)[9],BYTE bySource); // 正向;
  334. void ReturnBinaryReverseString(char (&szValue)[9],BYTE bySource); // 反向;
  335. string ReturnBinaryString(BYTE bySource); // 正向;
  336. string ReturnBinaryReverseString(BYTE bySource); // 反向;
  337. template <int nCount>
  338. void GetRealBitValue(char *szValue, const int &VLen,string &strBinary,const int &iSBit, const int &iEBit);
  339. template <int nCount>
  340. void GetVirtBitValue(char *szValue, const int &VLen,string &strBinary,const int &iSBit, const int &iEBit);
  341. private:
  342. //char m_szReturn[1024];
  343. public:
  344. // 字符大小写互换;
  345. void swapUpperLower(char *szMsg);
  346. // 字符全转为大写;
  347. void upperAllByte(char *szMsg);
  348. // 字符全转为小写;
  349. void lowerAllByte(char *szMsg);
  350. // 一串字符的每个字转换为两个16进制字节表示;
  351. void ByteToTwoByte( char *szMsg, char *szConvMsg );
  352. // 一串字符的每两个字节转换为一个字;
  353. void TwoByteToByte(char *szMsg, char *szConvMsg );
  354. // 十六进制Ascii字符转整数;
  355. //INT AsciiToBYTE(char szMsg);
  356. // 字符转ASCII;
  357. char ByteToAscii(BYTE btSrc);
  358. char lowercase2uppercase(BYTE btSrc);
  359. // 由数据精度获得浮点数的字符串值;
  360. CString GetDoubleText(double d);
  361. int DigitToBinary(WORD wdSource, char* pDes, int iBit) ;
  362. // 该函数把四位二进制转换成十六进制数;
  363. char Hex16(char WillChangeNum[]);
  364. // 将一串字符字母小写转大写;
  365. void strReverse( char *str );
  366. char twoHexByte2Word(char Hbyte,char Lbyte) ;
  367. void Str2HexStr(char *szHexString,char *szString,int *iHexStringLen);
  368. };
  369. void CCaluConvert::ReturnCorrectValue(char *szValue,const int &VLen,const double &dConfs,const double &dCrrect)
  370. {
  371. if ( dCrrect == 0.0 && dConfs == 0.0)
  372. return;
  373. double dValue = atof(szValue);
  374. if (dConfs == 0.0)
  375. {
  376. dValue += dCrrect;//校正处理;
  377. sprintf_s(szValue,VLen,"%f",dValue);
  378. return;
  379. }
  380. if ( dCrrect == 0.0)
  381. {
  382. dValue *= dConfs;
  383. sprintf_s(szValue,VLen,"%f",dValue);
  384. return;
  385. }
  386. dValue *= dConfs;
  387. dValue += dCrrect;
  388. sprintf_s(szValue,VLen,"%f",dValue);
  389. }
  390. INT CCaluConvert::ASCII_to_Byte(char c)
  391. {
  392. int iConvt = static_cast<int>(c);
  393. if ((c >= 'A')&&(c <= 'F'))
  394. iConvt = iConvt - 'A' + 10;
  395. else if ((c >= 'a')&&(c <= 'f'))
  396. iConvt = iConvt - 'a' + 10;
  397. else if ((c >= '0')&&(c <= '9'))
  398. iConvt -= '0';
  399. return iConvt;
  400. }
  401. // WORD
  402. WORD CCaluConvert::ReturnASCIIWORD(BYTE hBy,BYTE lBy)
  403. {
  404. // Z.t注意,hBy左移8位,会因为左边等式的类型而隐式转换成左边等式的类型;
  405. // 示例:hBy = 0x42,lBy = 0x31;
  406. // BYTE bValue = hBy << 8 | lBy;
  407. // 最后:bValue = 0x31;
  408. WORD wValue = hBy << 8 | lBy;
  409. return wValue;
  410. }
  411. WORD CCaluConvert::ReturnASCIIWORD(BYTE *bySource)
  412. {
  413. WORD wValue;
  414. wValue = bySource[0] << 8 | bySource[1] ;
  415. return wValue;
  416. }
  417. WORD CCaluConvert::ReturnASCIIWORD(BYTE *bySource,const int &iIndex)
  418. {
  419. WORD wValue;
  420. wValue = bySource[iIndex] << 8 | bySource[iIndex+1] ;
  421. return wValue;
  422. }
  423. // DWORD
  424. DWORD CCaluConvert::ReturnASCIIDWORD(WORD hWd,WORD lWd)
  425. {
  426. DWORD dwValue;
  427. dwValue = hWd << 16 | lWd;
  428. return dwValue;
  429. }
  430. void CCaluConvert::Literal(char *szValue,BYTE *szSource, const int &SLen)
  431. {
  432. memcpy(szValue,szSource,SLen);
  433. }
  434. void CCaluConvert::Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
  435. {
  436. double dRet = atof((char*)szSource);
  437. sprintf_s(szValue,VLen,"%f",dRet);
  438. }
  439. char CCaluConvert::TwoHexCharToChar(char ch1,char ch2)
  440. {
  441. char Numb1;
  442. char Numb2;
  443. if (ch1 >= 'A')
  444. Numb1 = (toupper(ch1)-'0'-7)*16;
  445. else
  446. Numb1 = (ch1 - '0')*16;
  447. if (ch2 >= 'A')
  448. Numb2 = (toupper(ch2) - '0' - 7);
  449. else
  450. Numb2 = (ch2 - '0');
  451. return (Numb1 + Numb2);
  452. }
  453. #endif