| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316 |
- #include "StdAfx.h"
- #include ".\caluconvert.h"
- BYTE *g_pSource = NULL; // 全局,用于动态创建内存;
- CCaluConvert::CCaluConvert(void)
- {
- }
- CCaluConvert::~CCaluConvert(void)
- {
- }
- void CCaluConvert::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)
- {
- if (dwCaluType/10000 != iCutLen)
- {
- sprintf_s(szDestValue,DestLen,"%s","截取长度与类型不匹配!");
- return;
- }
- int iBit_Over = iCutLen*8 -1;
- if ( iSBit > iBit_Over || iEBit > iBit_Over)
- {
- sprintf_s(szDestValue,DestLen,"%s","起始位与终止位超过有效位界限!");
- return;
- }
- if ( iSBit > iEBit)
- {
- sprintf_s(szDestValue,DestLen,"%s","起始位高于终止位!");
- return;
- }
- g_pSource = new BYTE[iCutLen];
- memcpy(g_pSource,szSourceValue + iIndex, iCutLen);
- switch(iCutLen)
- {
- case BYTE_1:
- _CONVERTORDER_1BYTE(szDestValue,DestLen, g_pSource, iSBit, iEBit, dConfs,dCrrect, dwCaluType);
- break;
- case BYTE_2:
- _CONVERTORDER_2BYTE(szDestValue,DestLen, g_pSource, iSBit, iEBit, dConfs,dCrrect, dwCaluType);
- break;
- case BYTE_3:
- _CONVERTORDER_3BYTE(szDestValue,DestLen, g_pSource, iSBit, iEBit, dConfs,dCrrect, dwCaluType);
- break;
- case BYTE_4:
- _CONVERTORDER_4BYTE(szDestValue,DestLen, g_pSource, iSBit, iEBit, dConfs,dCrrect, dwCaluType);
- break;
- case BYTE_5:
- _CONVERTORDER_5BYTE(szDestValue,DestLen, g_pSource, iSBit, iEBit, dConfs,dCrrect, dwCaluType);
- break;
- case BYTE_6:
- _CONVERTORDER_6BYTE(szDestValue,DestLen, g_pSource, iSBit, iEBit, dConfs,dCrrect, dwCaluType);
- break;
- case BYTE_7:
- _CONVERTORDER_7BYTE(szDestValue,DestLen, g_pSource, iSBit, iEBit, dConfs,dCrrect, dwCaluType);
- break;
- case BYTE_8:
- _CONVERTORDER_8BYTE(szDestValue,DestLen, g_pSource, iSBit, iEBit, dConfs,dCrrect, dwCaluType);
- break;
- default: // 默认->字符串,直接返回原串;
- break;
- }
- //end delete;
- delete []g_pSource;
- g_pSource = NULL;
- // 校正值(放在各函数内部,还是在此处理更优化); 做一个内联函数;
- ReturnCorrectValue(szDestValue,DestLen,dConfs,dCrrect);
- }
- // 1byte
- void CCaluConvert::_CONVERTORDER_1BYTE(char *&szValue,const int &VLen,BYTE *&szSource,const int &iSBit,const int &iEBit,const double &dConfs,const double &dCorrect,const DWORD &dwCaluType)
- {
- switch(dwCaluType)
- {
- case BYTE_1_RealBit:
- //_BYTE_1_RealBit(szValue, VLen, szSource, iSBit,iEBit);
- RealBit(szValue,VLen,szSource,BYTE_1,iSBit,iEBit);
- break;
- case BYTE_1_VirtBit:
- //_BYTE_1_VirtBit(szValue, VLen, szSource, iSBit,iEBit);
- VirtBit(szValue,VLen,szSource,BYTE_1,iSBit,iEBit);
- break;
- case BYTE_1_Literal: // 返回本身,不作任何处理;
- //_BYTE_1_Literal(szValue, VLen, szSource);
- Literal(szValue,szSource,1);
- break;
- case BYTE_1_Decimal:
- _BYTE_1_Decimal(szValue,VLen,szSource,dConfs);
- break;
- case BYTE_1_Literal_Decimal:
- //_BYTE_1_Literal_Decimal(szValue,VLen,szSource,dConfs);
- Literal_Decimal(szValue,VLen,szSource,dConfs);
- break;
- default:
- break;
- }
- }
- // 2byte
- void CCaluConvert::_CONVERTORDER_2BYTE(char *&szValue,const int &VLen,BYTE *&szSource,const int &iSBit,const int &iEBit,const double &dConfs,const double &dCorrect,const DWORD &dwCaluType)
- {
- switch(dwCaluType)
- {
- case BYTE_2_RealBit:
- //_BYTE_2_RealBit(szValue, VLen, szSource, iSBit, iEBit);
- RealBit(szValue,VLen,szSource,BYTE_2,iSBit,iEBit);
- break;
- case BYTE_2_VirtBit:
- //_BYTE_2_VirtBit(szValue, VLen, szSource, iSBit,iEBit);
- VirtBit(szValue,VLen,szSource,BYTE_2,iSBit,iEBit);
- break;
- case BYTE_2_Literal:
- //_BYTE_2_Literal(szValue, VLen, szSource);
- Literal(szValue,szSource,2);
- break;
- case BYTE_2_Decimal:
- _BYTE_2_Decimal(szValue, VLen, szSource,dConfs);
- break;
- case BYTE_2_Literal_Decimal:
- //_BYTE_1_Literal_Decimal(szValue,VLen,szSource,dConfs);
- Literal_Decimal(szValue,VLen,szSource,dConfs);
- break;
- case BYTE_2_MSByte:
- _BYTE_2_MSByte(szValue, VLen, szSource,dConfs);
- break;
- case BYTE_2_LSByte:
- _BYTE_2_LSByte(szValue, VLen, szSource,dConfs);
- break;
- case BYTE_2_1_RealBit:
- _BYTE_2_1_RealBit(szValue,VLen,szSource,iSBit,iEBit);
- break;
- case BYTE_2_1_VirtBit:
- _BYTE_2_1_VirtBit(szValue,VLen,szSource,iSBit,iEBit);
- break;
- case BYTE_2_1_Literal:
- _BYTE_2_1_Literal(szValue,VLen,szSource);
- break;
- case BYTE_2_1_Decimal:
- _BYTE_2_1_Decimal(szValue,VLen,szSource,dConfs);
- break;
- case BYTE_2_1_Literal_Decimal:
- _BYTE_2_1_Literal_Decimal(szValue,VLen,szSource,dConfs);
- break;
- default:
- break;
- }
- }
- // 3byte
- void CCaluConvert::_CONVERTORDER_3BYTE(char *&szValue,const int &VLen,BYTE *&szSource,const int &iSBit,const int &iEBit,const double &dConfs,const double &dCorrect,const DWORD &dwCaluType)
- {
- switch(dwCaluType)
- {
- case BYTE_3_RealBit:
- //_BYTE_3_RealBit(szValue, VLen, szSource, iSBit, iEBit);
- RealBit(szValue,VLen,szSource,BYTE_3,iSBit,iEBit);
- break;
- case BYTE_3_VirtBit:
- //_BYTE_3_VirtBit(szValue, VLen, szSource, iSBit, iEBit);
- VirtBit(szValue,VLen,szSource,BYTE_3,iSBit,iEBit);
- break;
- case BYTE_3_Literal:
- Literal(szValue,szSource,3);
- break;
- case BYTE_3_Decimal:
- _BYTE_3_Decimal(szValue,VLen,szSource,dConfs);
- break;
- case BYTE_3_Literal_Decimal:
- Literal_Decimal(szValue,VLen,szSource,dConfs);
- break;
- default:
- break;
- }
- }
- // 4byte
- void CCaluConvert::_CONVERTORDER_4BYTE(char *&szValue,const int &VLen,BYTE *&szSource,const int &iSBit,const int &iEBit,const double &dConfs,const double &dCorrect,const DWORD &dwCaluType)
- {
- switch(dwCaluType)
- {
- case BYTE_4_RealBit:
- //_BYTE_4_RealBit(szValue, VLen, szSource, iSBit, iEBit);
- RealBit(szValue,VLen,szSource,BYTE_4,iSBit,iEBit);
- break;
- case BYTE_4_VirtBit:
- //_BYTE_4_VirtBit(szValue, VLen, szSource, iSBit, iEBit);
- VirtBit(szValue,VLen,szSource,BYTE_4,iSBit,iEBit);
- break;
- case BYTE_4_Literal:
- Literal(szValue,szSource,4);
- break;
- case BYTE_4_Decimal:
- _BYTE_4_Decimal(szValue, VLen, szSource,dConfs);
- break;
- case BYTE_4_Literal_Decimal:
- Literal_Decimal(szValue,VLen,szSource,dConfs);
- break;
- case BYTE_4_Float:
- _BYTE_4_Float(szValue, VLen, szSource);
- default:
- break;
- }
- }
- // 5byte
- void CCaluConvert::_CONVERTORDER_5BYTE(char *&szValue,const int &VLen,BYTE *&szSource,const int &iSBit,const int &iEBit,const double &dConfs,const double &dCorrect,const DWORD &dwCaluType)
- {
- switch(dwCaluType)
- {
- case BYTE_5_RealBit:
- //_BYTE_5_RealBit(szValue, VLen, szSource, iSBit, iEBit);
- RealBit(szValue,VLen,szSource,BYTE_5,iSBit,iEBit);
- break;
- case BYTE_5_VirtBit:
- //_BYTE_5_VirtBit(szValue, VLen, szSource, iSBit, iEBit);
- VirtBit(szValue,VLen,szSource,BYTE_5,iSBit,iEBit);
- break;
- case BYTE_5_Literal:
- Literal(szValue, szSource,5);
- break;
- case BYTE_5_Decimal:
- _BYTE_5_Decimal(szValue, VLen, szSource,dConfs);
- break;
- case BYTE_5_Literal_Decimal:
- Literal_Decimal(szValue,VLen,szSource,dConfs);
- break;
- default:
- break;
- }
- }
- // 6byte
- void CCaluConvert::_CONVERTORDER_6BYTE(char *&szValue,const int &VLen,BYTE *&szSource,const int &iSBit,const int &iEBit,const double &dConfs,const double &dCorrect,const DWORD &dwCaluType)
- {
- switch(dwCaluType)
- {
- case BYTE_6_RealBit:
- //_BYTE_6_RealBit(szValue, VLen, szSource, iSBit, iEBit);
- RealBit(szValue,VLen,szSource,BYTE_6,iSBit,iEBit);
- break;
- case BYTE_6_VirtBit:
- //_BYTE_6_VirtBit(szValue, VLen, szSource, iSBit, iEBit);
- VirtBit(szValue,VLen,szSource,BYTE_6,iSBit,iEBit);
- break;
- case BYTE_6_Literal:
- Literal(szValue, szSource,6);
- break;
- case BYTE_6_Decimal:
- _BYTE_6_Decimal(szValue, VLen, szSource,dConfs);
- break;
- case BYTE_6_Literal_Decimal:
- Literal_Decimal(szValue,VLen,szSource,dConfs);
- break;
- default:
- break;
- }
- }
- // 7byte
- void CCaluConvert::_CONVERTORDER_7BYTE(char *&szValue,const int &VLen,BYTE *&szSource,const int &iSBit,const int &iEBit,const double &dConfs,const double &dCorrect,const DWORD &dwCaluType)
- {
- switch(dwCaluType)
- {
- case BYTE_7_RealBit:
- //_BYTE_7_RealBit(szValue, VLen, szSource, iSBit, iEBit);
- RealBit(szValue,VLen,szSource,BYTE_7,iSBit,iEBit);
- break;
- case BYTE_7_VirtBit:
- //_BYTE_7_VirtBit(szValue, VLen, szSource, iSBit, iEBit);
- VirtBit(szValue,VLen,szSource,BYTE_7,iSBit,iEBit);
- break;
- case BYTE_7_Literal:
- Literal(szValue, szSource,7);
- break;
- case BYTE_7_Decimal:
- _BYTE_7_Decimal(szValue, VLen, szSource,dConfs);
- break;
- case BYTE_7_Literal_Decimal:
- Literal_Decimal(szValue,VLen,szSource,dConfs);
- break;
- default:
- break;
- }
- }
- // 8byte
- void CCaluConvert::_CONVERTORDER_8BYTE(char *&szValue,const int &VLen, BYTE *&szSource,const int &iSBit,const int &iEBit,const double &dConfs,const double &dCorrect,const DWORD &dwCaluType)
- {
- switch(dwCaluType)
- {
- case BYTE_8_RealBit:
- //_BYTE_8_RealBit(szValue, VLen, szSource, iSBit, iEBit);
- RealBit(szValue,VLen,szSource,BYTE_8,iSBit,iEBit);
- break;
- case BYTE_8_VirtBit:
- //_BYTE_8_VirtBit(szValue, VLen, szSource, iSBit, iEBit);
- VirtBit(szValue,VLen,szSource,BYTE_8,iSBit,iEBit);
- break;
- case BYTE_8_Literal:
- Literal(szValue, szSource,8);
- break;
- case BYTE_8_Decimal:
- _BYTE_8_Decimal(szValue, VLen, szSource,dConfs);
- break;
- case BYTE_8_Literal_Decimal:
- Literal_Decimal(szValue,VLen,szSource,dConfs);
- break;
- case BYTE_8_4_Float:
- _BYTE_8_4_Float(szValue,VLen,szSource);
- break;
- default:
- break;
- }
- }
- /************************************************************************/
- void CCaluConvert::RealBit(char *szValue, const int &VLen,BYTE *szSource, const int &SLen, const int &iSBit,const int &iEBit)
- {
- string strBinary;
- for( int i = 0; i < SLen; i++)
- strBinary += ReturnBinaryReverseString(szSource[i]);
- switch(SLen)
- {
- case BYTE_1:
- GetRealBitValue<BYTE_1>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_2:
- GetRealBitValue<BYTE_2>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_3:
- GetRealBitValue<BYTE_3>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_4:
- GetRealBitValue<BYTE_4>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_5:
- GetRealBitValue<BYTE_5>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_6:
- GetRealBitValue<BYTE_6>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_7:
- GetRealBitValue<BYTE_7>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_8:
- GetRealBitValue<BYTE_8>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- }
- }
- void CCaluConvert::VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &SLen, const int &iSBit, const int &iEBit)
- {
- string strBinary;
- for( int i = 0; i < SLen; i++)
- //strBinary += ReturnBinaryReverseString(szSource[i]);
- strBinary += ReturnBinaryString(szSource[SLen-i-1]);
- switch(SLen)
- {
- case BYTE_1:
- GetVirtBitValue<BYTE_1>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_2:
- GetVirtBitValue<BYTE_2>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_3:
- GetVirtBitValue<BYTE_3>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_4:
- GetVirtBitValue<BYTE_4>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_5:
- GetVirtBitValue<BYTE_5>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_6:
- GetVirtBitValue<BYTE_6>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_7:
- GetVirtBitValue<BYTE_7>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- case BYTE_8:
- GetVirtBitValue<BYTE_8>(szValue,VLen,strBinary,iSBit,iEBit);
- break;
- }
- }
- //***************************1 字节*****************************************
- void CCaluConvert::_BYTE_1_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- int iSour = szSource[0];
- // 位顺序: 高->低 (7~0);
- bitset<8> bitSor(iSour);
- char szBinary[9] = {0};
- for ( int i = 0; i < 8; i++)
- szBinary[i] = bitSor[i];
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- for (int i = 0; i < 8; i++)
- if ( i < iSBit || i > iEBit)
- bitSor.reset(i);
- _itoa_s(bitSor.to_ulong(),szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_1_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- int iSour = szSource[0];
- // 位顺序: 高->低 (7~0);
- bitset<8> bitSor(iSour);
- char szBinary[9] = {0};
- for ( int i = 0; i < 8; i++)
- szBinary[i] = bitSor[i];
- iSour = 0;
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- for (int i = 0; i <= iEBit - iSBit; i++)
- iSour += szBinary[iSBit+i] * pow(2.0,i);
- _itoa_s(iSour,szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_1_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- double dRet = szSource[0];
- sprintf_s(szValue,VLen,"%f",dRet);
- }
- //***************************2 字节*****************************************
- void CCaluConvert::_BYTE_2_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- // 高在前,低在后;
- WORD wValue = ReturnASCIIWORD(szSource);
- bitset<16> bitSor(wValue);
- char szBinary[17] = {0};
- for ( int i = 0; i < 16; i++)
- szBinary[i] = bitSor[i];
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- for (int i = 0; i < 16; i++)
- if ( i < iSBit || i > iEBit)
- bitSor.reset(i);
- _itoa_s(bitSor.to_ulong(),szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_2_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- // 高在前,低在后;
- WORD wValue = ReturnASCIIWORD(szSource);
- bitset<16> bitSor(wValue);
- char szBinary[17] = {0};
- for ( int i = 0; i < 16; i++)
- szBinary[i] = bitSor[i];
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- int iSour = 0;
- for (int i = 0; i <= iEBit - iSBit; i++)
- iSour += szBinary[iSBit+i] * pow(2.0,i);
- _itoa_s(iSour,szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_2_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- // 高在前,低在后;
- WORD wValue = ReturnASCIIWORD(szSource);
- sprintf_s(szValue,VLen,"%d",wValue);
- }
- void CCaluConvert::_BYTE_2_MSByte(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- BYTE byValue = szSource[0];
- sprintf_s(szValue,VLen,"%f",byValue);
- }
- void CCaluConvert::_BYTE_2_LSByte(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- BYTE byValue = szSource[1];
- sprintf_s(szValue,VLen,"%f",byValue);
- }
- void CCaluConvert::_BYTE_2_1_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- // 高在前,低在后;
- BYTE byValue = ReturnASCIIByte(szSource);
- bitset<8> bitSor(byValue);
- char szBinary[9] = {0};
- for ( int i = 0; i < 8; i++)
- szBinary[i] = bitSor[i];
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- for (int i = 0; i < 8; i++)
- if ( i < iSBit || i > iEBit)
- bitSor.reset(i);
- _itoa_s(bitSor.to_ulong(),szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_2_1_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- // 高在前,低在后;
- BYTE byValue = ReturnASCIIByte(szSource);
- bitset<8> bitSor(byValue);
- //bitset<8> bitSor(*szSource);
- char szBinary[9] = {0};
- for ( int i = 0; i < 8; i++)
- szBinary[i] = bitSor[i];
- int iSour = 0;
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- for (int i = 0; i <= iEBit - iSBit; i++)
- iSour += szBinary[iSBit+i] * pow(2.0,i);
- _itoa_s(iSour,szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_2_1_Literal(char *szValue, const int &VLen, BYTE *szSource)
- {
- BYTE byValue = ReturnASCIIByte(szSource);
- szValue[0] = byValue;
- //memcpy(szValue,&byValue,BYTE_1);
- }
- void CCaluConvert::_BYTE_2_1_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- BYTE byValue = ReturnASCIIByte(szSource);
- double dRet = byValue;
- sprintf_s(szValue,VLen,"%f",dRet);
- }
- void CCaluConvert::_BYTE_2_1_Literal_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- BYTE byValue = ReturnASCIIByte(szSource);
- double dRet = atof((char*)&byValue);
- sprintf_s(szValue,VLen,"%f",dRet);
- }
- //***************************3 字节*****************************************
- void CCaluConvert::_BYTE_3_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- // 高在前,低在后;
- DWORD dwValue = szSource[0] << 16 | szSource[1] << 8 | szSource[2];
- bitset<32> bitSor(dwValue);
- char szBinary[33] = {0};
- for ( int i = 0; i < 32; i++)
- szBinary[i] = bitSor[i];
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- for (int i = 0; i < 32; i++)
- if ( i < iSBit || i > iEBit)
- bitSor.reset(i);
- _itoa_s(bitSor.to_ulong(),szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_3_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- DWORD dwValue = szSource[0] << 16 | szSource[1] << 8 | szSource[2];
- bitset<32> bitSor(dwValue);
- char szBinary[33] = {0};
- for ( int i = 0; i < 32; i++)
- szBinary[i] = bitSor[i];
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- int iSour = 0;
- for (int i = 0; i <= iEBit - iSBit; i++)
- iSour += szBinary[iSBit+i] * pow(2.0,i);
- _itoa_s(iSour,szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_3_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- DWORD dwValue = szSource[0] << 16 | szSource[1] << 8 | szSource[2];
- sprintf_s(szValue,VLen,"%d",dwValue);
- }
- //***************************4 字节*****************************************
- void CCaluConvert::_BYTE_4_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- DWORD dwValue = ReturnASCIIDWORD(szSource);
- bitset<32> bitSor(dwValue);
- char szBinary[33] = {0};
- for ( int i = 0; i < 32; i++)
- szBinary[i] = bitSor[i];
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- for (int i = 0; i < 32; i++)
- if ( i < iSBit || i > iEBit)
- bitSor.reset(i);
- _itoa_s(bitSor.to_ulong(),szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_4_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- DWORD dwValue = ReturnASCIIDWORD(szSource);
- bitset<32> bitSor(dwValue);
- char szBinary[33] = {0};
- for ( int i = 0; i < 32; i++)
- szBinary[i] = bitSor[i];
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- int iSour = 0;
- for (int i = 0; i <= iEBit - iSBit; i++)
- iSour += szBinary[iSBit+i] * pow(2.0,i);
- _itoa_s(iSour,szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_4_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- DWORD dwValue = ReturnASCIIDWORD(szSource);
- sprintf_s(szValue,VLen,"%d",dwValue);
- }
- void CCaluConvert::_BYTE_4_Float(char *szValue, const int &VLen,BYTE *szSource)
- {
- float fValue = *(float*)szSource;
- sprintf_s(szValue,VLen,"%f",fValue);
- }
- //***************************5 字节*****************************************
- void CCaluConvert::_BYTE_5_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- string strBinary;
- for( int i = 0; i < BYTE_5; i++)
- strBinary += ReturnBinaryReverseString(szSource[i]);
- bitset<40> bitSor(strBinary);
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- for (int i = 0; i < 40; i++)
- if ( i < iSBit || i > iEBit)
- bitSor.reset(i);
- _itoa_s(bitSor.to_ulong(),szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_5_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- string strBinary;
- for( int i = 0; i < BYTE_5; i++)
- strBinary += ReturnBinaryReverseString(szSource[i]);
- bitset<40> bitSor(strBinary);
- int dwSour = 0;
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- string::reverse_iterator rit;
- rit = strBinary.rbegin() + iSBit;
- for (int i = 0; i <= iEBit - iSBit; i++,rit++)
- dwSour += (*rit - 48) * pow(2.0,i);
- _itoa_s(dwSour,szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_5_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- VirtBit(szValue, VLen, szSource, BYTE_5, 0, 8*BYTE_5 -1);
- }
- //***************************6 字节*****************************************
- void CCaluConvert::_BYTE_6_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- string strBinary;
- for( int i = 0; i < BYTE_6; i++)
- strBinary += ReturnBinaryReverseString(szSource[i]);
- bitset<48> bitSor(strBinary);
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- for (int i = 0; i < 48; i++)
- if ( i < iSBit || i > iEBit)
- bitSor.reset(i);
- _itoa_s(bitSor.to_ulong(),szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_6_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- string strBinary;
- for( int i = 0; i < BYTE_6; i++)
- strBinary += ReturnBinaryReverseString(szSource[i]);
- bitset<48> bitSor(strBinary);
- int dwSour = 0;
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- string::reverse_iterator rit;
- rit = strBinary.rbegin() + iSBit;
- for (int i = 0; i <= iEBit - iSBit; i++,rit++)
- dwSour += (*rit - 48) * pow(2.0,i);
- _itoa_s(dwSour,szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_6_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- VirtBit(szValue,VLen,szSource,BYTE_6,0,8*BYTE_6-1);
- }
- //***************************7 字节*****************************************
- void CCaluConvert::_BYTE_7_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- string strBinary;
- for( int i = 0; i < BYTE_7; i++)
- strBinary += ReturnBinaryReverseString(szSource[i]);
- bitset<56> bitSor(strBinary);
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- for (int i = 0; i < 56; i++)
- if ( i < iSBit || i > iEBit)
- bitSor.reset(i);
- _itoa_s(bitSor.to_ulong(),szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_7_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- string strBinary;
- for( int i = 0; i < BYTE_7; i++)
- strBinary += ReturnBinaryReverseString(szSource[i]);
- bitset<56> bitSor(strBinary);
- int dwSour = 0;
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- string::reverse_iterator rit;
- rit = strBinary.rbegin() + iSBit;
- for (int i = 0; i <= iEBit - iSBit; i++,rit++)
- dwSour += (*rit - 48) * pow(2.0,i);
- _itoa_s(dwSour,szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_7_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- VirtBit(szValue,VLen,szSource,BYTE_7,0,8*BYTE_7-1);
- }
- //***************************8 字节*****************************************
- void CCaluConvert::_BYTE_8_RealBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- string strBinary;
- for( int i = 0; i < BYTE_8; i++)
- strBinary += ReturnBinaryReverseString(szSource[i]);
- bitset<64> bitSor(strBinary);
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- for (int i = 0; i < 64; i++)
- if ( i < iSBit || i > iEBit)
- bitSor.reset(i);
- _itoa_s(bitSor.to_ulong(),szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_8_VirtBit(char *szValue, const int &VLen, BYTE *szSource, const int &iSBit, const int &iEBit)
- {
- string strBinary;
- for( int i = 0; i < BYTE_8; i++)
- strBinary += ReturnBinaryReverseString(szSource[i]);
- bitset<64> bitSor(strBinary);
- int dwSour = 0;
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%d",(int)bitSor[iSBit]);
- return;
- }
- else
- {
- string::reverse_iterator rit;
- rit = strBinary.rbegin() + iSBit;
- for (int i = 0; i <= iEBit - iSBit; i++,rit++)
- dwSour += (*rit - 48) * pow(2.0,i);
- _itoa_s(dwSour,szValue,VLen,10);
- }
- }
- void CCaluConvert::_BYTE_8_Decimal(char *szValue, const int &VLen, BYTE *szSource, const double &dConfs)
- {
- VirtBit(szValue,VLen,szSource,BYTE_8,0,8*BYTE_8-1);
- }
- void CCaluConvert::_BYTE_8_4_Float(char *szValue, const int &VLen, BYTE *szSource)
- {
- ReturnFloat_8Byte(szValue,VLen,szSource);
- }
- /************************************************************************/
- BYTE CCaluConvert::ReturnASCIIByte(BYTE hBy,BYTE lBy)
- {
- BYTE byValue;
- byValue = (ASCII_to_Byte(hBy) << 4) | ASCII_to_Byte(lBy);
- return byValue;
- }
- BYTE CCaluConvert::ReturnASCIIByte(BYTE *bySource)
- {
- BYTE byValue;
- byValue = (ASCII_to_Byte(bySource[0]) << 4) | ASCII_to_Byte(bySource[1]);
- /*BYTE byValue,hBy,lBy;
- hBy = bySource[0];
- lBy = bySource[1];
- byValue = (ASCII_to_Byte(hBy) << 4) | ASCII_to_Byte(lBy);*/
- return byValue;
- }
- BYTE CCaluConvert::ReturnASCIIByte(BYTE *bySource,const int &iIndex)
- {
- BYTE byValue;
- byValue = (ASCII_to_Byte(bySource[iIndex]) << 4) | ASCII_to_Byte(bySource[iIndex+1]);
- /*BYTE byValue,hBy,lBy;
- hBy = bySource[iIndex];
- lBy = bySource[iIndex+1];
- byValue = (ASCII_to_Byte(hBy) << 4) | ASCII_to_Byte(lBy);*/
- return byValue;
- }
- DWORD CCaluConvert::ReturnASCIIDWORD(BYTE *bySource)
- {
- DWORD dwValue;
- dwValue = ReturnASCIIWORD(bySource,0) << 16 | ReturnASCIIWORD(bySource,2);
- /*WORD hWd,lWd;
- hWd = ReturnASCIIWORD(bySource,0);
- lWd = ReturnASCIIWORD(bySource,2);
- dwValue = hWd << 16 | lWd;*/
- return dwValue;
- }
- DWORD CCaluConvert::ReturnASCIIDWORD(BYTE *bySource,const int &iIndex)
- {
- DWORD dwValue;
- dwValue = ReturnASCIIWORD(bySource+iIndex,0) << 16 | ReturnASCIIWORD(bySource+iIndex+1,2);
- return dwValue;
- }
- void CCaluConvert::ReturnBinaryString(char (&szValue)[9], BYTE bySource)
- {
- bitset<8> bitSor(bySource);
- for ( int i = 0; i < 8; i++)
- szValue[i] = bitSor[i];
- }
- string CCaluConvert::ReturnBinaryString( BYTE bySource)
- {
- string strBinary;
- strBinary.resize(8);
- bitset<8> bitSor(bySource);
- for ( int i = 0; i < 8; i++)
- strBinary[i] = bitSor[i] + 48;
- return strBinary;
- }
- void CCaluConvert::ReturnBinaryReverseString(char (&szValue)[9], BYTE bySource)
- {
- bitset<8> bitSor(bySource);
- for ( int i = 0; i < 8; i++)
- szValue[i] = bitSor[7-i];
- }
- string CCaluConvert::ReturnBinaryReverseString( BYTE bySource)
- {
- string strBinary;
- strBinary.resize(8);
- bitset<8> bitSor(bySource);
- for ( int i = 0; i < 8; i++)
- strBinary[i] = bitSor[7-i] + 48;
- return strBinary;
- }
- template <int nCount>
- void CCaluConvert::GetRealBitValue(char *szValue, const int &VLen,string &strBinary,const int &iSBit, const int &iEBit)
- {
- bitset<8*nCount> bitSor(strBinary);
- if ( iSBit == iEBit)
- {
- for (int i = 0; i < 8*nCount; i++)
- if ( i < iSBit || i > iEBit)
- bitSor.reset(i);
- _itoa_s(bitSor.to_ulong(),szValue,VLen,10);
- return;
- }
- else
- {
- for (int i = 0; i < 8*nCount; i++)
- if ( i < iSBit || i > iEBit)
- bitSor.reset(i);
-
- _itoa_s(bitSor.to_ulong(),szValue,VLen,10); // to_ulong只返回32位有效数,超过将出错;
- }
- }
- template <int nCount>
- void CCaluConvert::GetVirtBitValue(char *szValue, const int &VLen,string &strBinary,const int &iSBit, const int &iEBit)
- {
- bitset<8*nCount> bitSor(strBinary);
- if ( iSBit == iEBit)
- {
- sprintf_s(szValue,VLen,"%c",strBinary[iSBit]);
- return;
- }
- else
- {
- int iBitLen = iEBit - iSBit;
- #if 0
- __int64 _i64_Sour = 0;
- string::reverse_iterator rit;
- rit = strBinary.rbegin() + iSBit;
- for (int i = 0; i <= iBitLen; i++,rit++)
- _i64_Sour += (*rit - 48) * pow(2.0,i);
- //_itoa_s(_i64_Sour,szValue,VLen,10);
- //_ultoa_s(_i64_Sour,szValue,VLen,10);
- sprintf_s(szValue,VLen,"%llu",_i64_Sour);
- #else
- int int_dat = 0;
- long double ldValue = 0.0;
- for ( int i = 0; i <= iBitLen; i++)
- {
- int_dat = strBinary[iSBit+i] - 48;
- if (int_dat == 0)
- continue;
- ldValue += int_dat*pow(2.0,i);
- }
- sprintf_s(szValue,VLen,"%llf",ldValue);
- #endif
- }
- }
- void CCaluConvert::ReturnFloat_8Byte(char *szValue, const int &VLen, BYTE *szSource)
- {
- union
- {
- float fNum ;
- BYTE ch[4];
- }uBtoF;
- BYTE ch[8] = {0};
- memcpy(ch, szSource, 8);
- uBtoF.ch[0] = ReturnASCIIByte(szSource[0],szSource[1]);
- uBtoF.ch[1] = ReturnASCIIByte(szSource[2],szSource[3]);
- uBtoF.ch[2] = ReturnASCIIByte(szSource[4],szSource[5]);
- uBtoF.ch[3] = ReturnASCIIByte(szSource[6],szSource[7]);
- sprintf_s(szValue,VLen,"%f",uBtoF.fNum);
- }
- /************************************************************************/
- void CCaluConvert::swapUpperLower(char *szMsg)
- {
- for (int i = 0; i< (int)strlen(szMsg); i++)
- {
- if ((szMsg[i] >= 'A') && (szMsg[i] <= 'Z'))
- szMsg[i] = szMsg[i] + 32;
- else if ((szMsg[i] >= 'a') && (szMsg[i] <= 'z'))
- szMsg[i] = szMsg[i] - 32;
- else
- szMsg[i] = szMsg[i];
- }
- }
- void CCaluConvert::upperAllByte(char *szMsg)
- {
- for (int i=0; i < static_cast<int>(strlen(szMsg)); i++)
- {
- if ((szMsg[i] >= 'a') && (szMsg[i] <= 'z'))
- szMsg[i] = szMsg[i] - 32;
- else
- szMsg[i] = szMsg[i];
- }
- }
- void CCaluConvert::lowerAllByte(char *szMsg)
- {
- for (int i=0; i < static_cast<int>(strlen(szMsg)); i++)
- {
- if ((szMsg[i]>='A') && (szMsg[i]<='Z'))
- szMsg[i] = szMsg[i] + 32;
- else
- szMsg[i] = szMsg[i];
- }
- }
- void CCaluConvert::ByteToTwoByte( char *szMsg, char *szConvMsg )
- {
- char ch[3];
- for (int i=0; i < static_cast<int>(strlen(szMsg)); i++)
- {
- memset(ch, 0, 3);
- _itoa_s(static_cast<int>(szMsg[i]), ch, 3, 16);
- szConvMsg[i*2] = ch[0];
- szConvMsg[i*2 + 1] = ch[1];
- }
- }
- void CCaluConvert::TwoByteToByte(char *szMsg, char *szConvMsg )
- {
- for (int i=0; i< static_cast<int>(strlen(szMsg)/2); i++)
- szConvMsg[i] = szMsg[i*2] << 4 | szMsg[i*2 + 1];
- }
- char CCaluConvert::ByteToAscii(BYTE btSrc)
- {
- char chDest;
- if( btSrc < 10 )
- {
- chDest = static_cast<char>(btSrc % 10 + '0');
- chDest = lowercase2uppercase(chDest);
- return chDest;
- }
- else
- {
- chDest = ByteToAscii( btSrc / 10 ) + static_cast<char>( btSrc % 10 + '0' );
- chDest = lowercase2uppercase(chDest);
- return chDest;
- }
- }
- char CCaluConvert::lowercase2uppercase(BYTE btSrc)
- {
- if( btSrc >= 'a' && btSrc <= 'z' )
- return btSrc - 'a' + 'A';
- return btSrc;
- }
- CString CCaluConvert::GetDoubleText(double d)
- {
- CString strRtn;
- CString strFmt;
- int g_nPrecision = -1;
- if(g_nPrecision == 0)
- strFmt = "%g";
- else
- {
- long lV = static_cast<long>(fabs(d));
- if(lV >= 1)
- {
- int nIntBit = 0;
- while(lV >= 1)
- {
- lV = lV/10;
- nIntBit++;
- }
- if(nIntBit < g_nPrecision)
- strFmt.Format("%c%d.%df", '%', nIntBit, (g_nPrecision-nIntBit));
- else
- strFmt.Format("%c%d.0f", '%', nIntBit);
- }
- else
- {
- double dTemp = fabs(d);
- if(dTemp > 0.00000000001)
- {
- int nDot0Bit = 0;
- while(dTemp < 0.1)
- {
- dTemp = dTemp*10;
- nDot0Bit++;
- }
- strFmt.Format("%c1.%df", '%', nDot0Bit + g_nPrecision);
- }
- else
- {
- strFmt = "%g";
- }
- }
- }
- strRtn.Format(strFmt, d);
- return strRtn;
- }
- char CCaluConvert::Hex16(char WillChangeNum[]) //该函数把四位二进制转换成十六进制数;
- {
- int i;
- i = (WillChangeNum[3]) + (WillChangeNum[2] * 10) +
- (WillChangeNum[1] * 100) + (WillChangeNum[0] * 1000);
- switch(i)
- {
- case 0:
- return 0;
- case 1:
- return 1;
- case 10:
- return 2;
- case 11:
- return 3;
- case 100:
- return 4;
- case 101:
- return 5;
- case 110:
- return 6;
- case 111:
- return 7;
- case 1000:
- return 8;
- case 1001:
- return 9;
- case 1010:
- return 0x0A;
- case 1011:
- return 0x0B;
- case 1100:
- return 0x0C;
- case 1101:
- return 0x0D;
- case 1110:
- return 0x0E;
- case 1111:
- return 0x0F;
- }
- return -1;
- }
- void CCaluConvert::strReverse( char *str )
- {
- int l = (int)strlen(str);
- for( int i = 0; i < l; i++ )
- {
- for(int i = 0; i < l; i++)
- {
- if( str[i] >= 'A' && str[i] <= 'Z' )
- str[i] += 32;
- else if(str[i] >= 'a' && str[i] <= 'z')
- str[i] -= 32;
- }
- }
- }
- char CCaluConvert::twoHexByte2Word(char Hbyte,char Lbyte)
- {
- char Numb1;
- char Numb2;
- if (Hbyte >= 'A')
- Numb1 = (toupper(Hbyte)-'0'-7)*16;
- else
- Numb1 = (Hbyte - '0')*16;
- if (Lbyte >= 'A')
- Numb2 = (toupper(Lbyte) - '0' - 7);
- else
- Numb2 = (Lbyte - '0');
- return (Numb1 + Numb2);
- }
- void CCaluConvert::Str2HexStr(char *szHexString,char *szString,int *iHexStringLen)
- {
- int iLoop;
- int iCount;
-
- iLoop = 0;
- iCount = 0;
- szHexString[0] = '\0';
-
- while(1)
- {
- if (szString[iLoop] == '\0' || szString[iLoop + 1] == '\0')
- break;
-
- szHexString[iCount] = static_cast<char>(twoHexByte2Word(szString[iLoop],szString[iLoop + 1]));
- iLoop ++;
- iLoop ++;
- iCount ++;
- }
-
- szHexString[iCount] = '\0';
-
- *iHexStringLen = iCount;
- }
|