Borrar filtros
Borrar filtros

how to convert 2 double number and packed in 32 bit

13 visualizaciones (últimos 30 días)
rps rathore
rps rathore el 21 de Ag. de 2015
Comentada: rps rathore el 27 de Ag. de 2015
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 comentarios
Walter Roberson
Walter Roberson el 21 de Ag. de 2015
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 el 24 de Ag. de 2015
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

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Ag. de 2015
Editada: Walter Roberson el 21 de Ag. de 2015
typecast(int16(x*2^14),'uint32')
is one possibility depending on what you mean by 16,14
  3 comentarios
Walter Roberson
Walter Roberson el 24 de Ag. de 2015
typecast(storedInteger([FirstFi, SecondFi]),'uint32')
or you might need
typecast([storedInteger(FirstFi), storedInteger(SecondFi)], 'uint32')
rps rathore
rps rathore el 27 de Ag. de 2015
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

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by