How to convert 8 bytes to a double value

Hi,
Matlab script takes values from an udp server. Server respond contains 8 bytes so it is needed to convert this 8 bytes to an double value in matlab script.
My script:
u = udp('127.0.0.1', 49012, 'LocalPort', 85);
fopen(u);
fprintf(u,"request");
data = fread(u); % reads 8 bytes
data = typecast(str2num(sprintf('%d%d%d%d%d%d%d%d',data(1),data(2),data(3),data(4),data(5),data(6),data(7),data(8))), 'double');
disp(data)
for example its received data is as follows:
147, 190, 144, 143, 145, 126, 68, 64
It is converted to double as
1.4719e+21
but orginal value is about to 41
Note: There is no problem in server. I tested it using C# and received correct results.
Note: Reading value as double was tried like as follows:
fread(u, size, 'double')
However, this method does not make any difference.

 採用された回答

Bruno Luong
Bruno Luong 2020 年 11 月 5 日

0 投票

>> typecast(uint8([147, 190, 144, 143, 145, 126, 68, 64]),'double')
ans =
40.9888

2 件のコメント

John Smith
John Smith 2020 年 11 月 5 日
thank you
Yelile Iga
Yelile Iga 2022 年 10 月 9 日
we have the same poblem, can you help us?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

質問済み:

2020 年 11 月 5 日

コメント済み:

2022 年 10 月 9 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by