MATLAB将大端顺序字节转换为浮点值 [英] MATLAB convert big-endian order bytes into floating point values
本文介绍了MATLAB将大端顺序字节转换为浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
data = [189 33 136 147]
这4个字节代表Big-endian顺序的单个浮点数。我怎样才能得到这个数字在MATLAB?
我需要连接和转换。我尝试过:
pre code $ x = ,data(2),data(3),data(4))),'single')
无济于事(我得到了 x = []
)。
解决方案
很好的例子 here:
>> dataL = typecast(uint8([189,33,136,147]),'uint32')
dataL =
2475172285
>> dataF = double(dataL)
dataF =
2.4752e + 09
big到很少,尝试 swapbytes
>> dataLbig = swapbytes(dataL)
dataLbig =
3173091475
>> dataFbig = double(dataLbig)
dataFbig =
3.1731e + 09
这是你所期待的?
I have the following bytes stored in a vector:
data = [189 33 136 147]
These 4 bytes represent a single float in Big-endian order. How can I get this number in MATLAB?
I will need to concatenate and convert. I tried:
x = typecast(str2num(sprintf('%d%d%d%d',data(1),data(2),data(3),data(4))), 'single')
To no avail (I got x = []
).
解决方案
great example here:
>> dataL = typecast(uint8([189, 33, 136, 147]), 'uint32')
dataL =
2475172285
>> dataF = double(dataL)
dataF =
2.4752e+09
big to little, try swapbytes
>> dataLbig = swapbytes(dataL)
dataLbig =
3173091475
>> dataFbig = double(dataLbig)
dataFbig =
3.1731e+09
Is this what you were expecting?
这篇关于MATLAB将大端顺序字节转换为浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文