how to convert 2 double number and packed in 32 bit

22 次查看(过去 30 天)
hi i want to convert 2 double number 0.5 and -0.5 in 16 bit and packed into 32 bit. each number in double takes 8 bytes. i want to convert in this number in fixed point 16,14 (2 bytes). and finally i want to packed these 2 number in 32 bit(4 bytes). please tell me how i can do this operation in matlab
  2 个评论
Walter Roberson
Walter Roberson 2015-8-21
Does 16,14 indicate 1 sign bit, then 1 bit of integer, then 14 bits of fraction? Or do you want to use 2s complement?
rps rathore
rps rathore 2015-8-24
yes my number is 16 bit in which 1 is sign bit , 1 bit integer part and 14 bit fractional part. my number range is +2 to -2. i am converting double number into fixed point number using sfi(Num,16,14); how to pack two 16 bits fixed point number in 32 bit .i packed this number beacuse i want to send this number by udp

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2015-8-21
编辑:Walter Roberson 2015-8-21
typecast(int16(x*2^14),'uint32')
is one possibility depending on what you mean by 16,14
  3 个评论
Walter Roberson
Walter Roberson 2015-8-24
typecast(storedInteger([FirstFi, SecondFi]),'uint32')
or you might need
typecast([storedInteger(FirstFi), storedInteger(SecondFi)], 'uint32')
rps rathore
rps rathore 2015-8-27
thanks for replying . i have some problem in above equation. i am converting double number into fixed point using a=sfi(0.5,16,14) b=sfi(-0.5,16,14). i am converting fixed number into decimal and hex using hex(a) ans = 2000 dec(a) ans =08192, hex(b) ans =e000 dec(b) ans =57344. i am using your suggested equation for packing two fixed number into 32 bits c=typecast([storedInteger(a), storedInteger(b)], 'uint32')
c = 3758104576. This answer i am not able to interpret in decimal or hex.| if i am using hex function.it gave error hex(c) Undefined function 'hex' for input arguments of type 'uint32'. if i am using num2hex function.it gave error num2hex(c) Error using num2hex (line 32) Inputs must be floating point, and may not be of class uint32.
if i packed 2 number in 32 bit answer is in hex 2000e000, or in decimal 536928256. but i am not getting how i get this number 3758104576 using c=typecast([storedInteger(a),storedInteger(b)], 'uint32'). please help me how to interpret this number and explain how it is work

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by