MATLAB convert big-endian order bytes into floating point values

后端 未结 2 922
感情败类
感情败类 2021-01-06 21:57

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. H

2条回答
  •  孤独总比滥情好
    2021-01-06 22:20

    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?

提交回复
热议问题