2016-11-20 79 views
0

我正在對Hytera dmr中繼器運行多個SNMP查詢。但是,SNMP對象定義是這樣的:將SNMP八位字符串轉換爲浮點(可讀字符串)

rptVswr OBJECT-TYPE 
     SYNTAX OCTET STRING(SIZE(4)) 
     MAX-ACCESS read-only 
     STATUS mandatory 
     DESCRIPTION 
       "The VSWR. 
       It should be changed to float format. " 
     -- 1.3.6.1.4.1.40297.1.2.1.2.4 
     ::= { rptDataInfo 4 } 

運行查詢後,我得到了這樣的結果:

Name/OID: rptVswr.0; 
Value (OctetString): 0x76 D5 8B 3F 

有沒有人有一個想法如何給字符串轉換成可讀格式? 它應該是這樣的:1.15 or 2.15

非常感謝您的幫助,

BR - 尼爾斯

回答

0

這裏是非常解碼十六進制數據並將其轉換爲浮動簡單的C++應用程序:

#include <iostream> 
#include <algorithm> 

using namespace std; 

int main() 
{ 
    unsigned char ptr[] = {0x76, 0xD5, 0x8B, 0x3F}; 
    reverse(ptr, ptr + 4); 
    float f = *reinterpret_cast<float*>(ptr); 

    cout << f << endl; 

    return 0; 
} 

結果是2.16559e+33