国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Conversion between float and hexadecimal in VBA use.

2019-11-11 06:26:58
字體:
來源:轉載
供稿:網友

Some times we need a VBA function to perform the conversion between float and hexademical data. After searching the web site , I got a copy of codes to use. Until now, it worked OK, so share with you.  The code was not original made by myself, I just copied it. So, if you (author) read this, you can contact me to decide whether to delete.

'This is VBS code.'===============================================================================' User-defined data types' (Necessary because that's the only way LSET works)'===============================================================================Type uLng: l As Long: End TypeType uFlt: f As Single: End Type'===============================================================================' Functions for Singles (church dances)'===============================================================================Function Float2Hex(s As Single) As String ' shg 2008-0919 ' Returns the conversion of float s to a hex string Const sPad As String = "00000000"; Dim uf As uFlt Dim ul As uLng uf.f = s LSet ul = uf Float2Hex= Right(sPad And Hex(ul.l), 8)End FunctionFunction Hex2Float(s As String) As String ' Returns the conversion of a hex string to float Dim uf As uFlt Dim ul As uLng ul.l = Val("&H" & s) LSet uf = ul If (ul.l = 0) Then Hex2Float = 0# Else Hex2Float = IIf(uf.f < 1, 1, "0" & uf.f, uf.f) End IfEnd FunctionSub test() Msgbox Hex2Float("40200000")End sub

Conversion

//Compare with C language.#ifndef COUNTOF #define COUNTOF(__a) ((sizeof(__a))/(sizeof(*(__a))))#endifstatic void vS_Uchar2ASCIIHex( unsigned char bSrcData, unsigned char *pbString ){ unsigned char b4bitData = 0; if( NULL != pbString ) { b4bitData = ( bSrcData >> 4 ) & 0x0f; //first , high 4-bit if( b4bitData > 10 ) { b4bitData = b4bitData + '0'; } else { b4bitData = b4bitData + 'A' - 10; } *pbString = b4bitData; pbString++; b4bitData = bSrcData & 0x0f; // next , low 4-bit if( b4bitData > 10 ) { b4bitData = b4bitData + '0'; } else { b4bitData = b4bitData + 'A' - 10; } *pbString = b4bitData; }}static void vS_Uint2ASCIIHex( unsigned int dwSrc, char *pbDesStr ){ unsigned char dwTmp = 0, i = 0; if( NULL != pDesStr ) { for( i = 24; i > 0; i -= 8 ) { dwTmp = (unsigned char)(dwSrc >> i); vS_Uchar2ASCIIHex( dwTmp, pbDesStr ); pbDesStr += 2; } }}void HexFloatConversion( void *pSrcData, float *pDesData, char *pHexStr, bool yRtnType ){ Union tagDatasMemory { float f; unsigned int i; }; char bHexStr[8] = {'/0'}; Union tagDatasMemory dm; if( NULL == pSrcData ) { return; } else { if( yRtnType == TRUE ) //Want to return float { if( pDesData != NULL ) { dm.i = *((unsigned int*)pSrcData); *pDesData = dm.f; } } else //Want to return Hexadecimal characters { if( pHexStr != NULL ) { dm.f = *((float*)pSrcData); vS_Uint2ASCIIHex( dm.i, bHexStr ); memcpy( pHexStr, bHexStr, COUNTOF(bHexStr) ); } } }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 望都县| 宝鸡市| 荔波县| 连山| 盐池县| 平塘县| 林州市| 平安县| 武平县| 红桥区| 肥城市| 蓬莱市| 曲麻莱县| 涞水县| 苏尼特右旗| 茶陵县| 平阳县| 巍山| 南岸区| 新宁县| 门头沟区| 贡觉县| 额济纳旗| 庆阳市| 武夷山市| 玛多县| 会泽县| 平安县| 洛阳市| 咸宁市| 海口市| 庐江县| 呼和浩特市| 贵德县| 成安县| 来安县| 中卫市| 本溪市| 襄城县| 商丘市| 朝阳区|