0
我將從UDP消息中提取/解壓浮動數並使用解壓縮。接收到的浮點值未正確解碼。 該收到的值的示例:Python從UDP消息中解壓十六進制浮點數
value_1; value_2; value_3; value_4; value_5; value_6; value_7; value_8; value_9
113; 25; 99; -5,935507590692059e-21; 3,6735358238220215; 9,607040496462105e-09; 3,105335657942221e+16; 1,677943189259233e-31; -1,1667551647054353e-10; 158
113; 25; 99; 1,6007581002917826e-13; -2,7373925907322235e+32; -5,90081314613487e+37; -1,1715147514317771e-33; -84894,453125; 1,6881092411861532e-15; 214
113; 25; 99; 89819568,0; -7,121651712793664e-09; -1,0874276739486488e-12; 5,0595508846403285e+31; 7,212918281555176; -9,193915300799425e-38; 21
的113,圖25和99是正確的,並且最後的值是校驗和也是正確的。
作爲下一個示例,浮點數應該更像0.0003234的值。
-1.5357945225e-004 -2.3622182564e-004 8.0991359160e-005 -1.4786999673e-003 2.0443745889e-003 4.9047302455e-002
1.9647086933e-004 -2.3016422241e-004 3.8992474000e-004 -1.4826891711e-003 2.0534156356e-003 4.9040760845e-002
1.3971551841e-004 -6.4107143726e-005 3.6151042455e-004 -1.4849692816e-003 2.0616210531e-003 4.9035679549e-002
如何提取此數據中正確的浮點數?
這裏是我的代碼的必要:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP,UDP_PORT))
f.write("'value_1', value_2, value_3, value_4, value_5, value_6, value_7, value_8, value_9" '\n')
while i < NumberOfSamples:
data, addr = sock.recvfrom(4096) # buffer size is 1024 bytes
print >>f, struct.unpack("<BBBffffffB", data)
for line in f:
f2.write(line.replace(',',';').replace('.',',').replace('(',' ').replace(')',' '))
那麼,什麼是你的預期輸出'打印 「{:.20f}」。格式(struct.unpack( 「> F」, 「\ xb6 \ xd5 \ x38 \ x53」)[0])'?我得到了'-0.00000635445167063153' –