Clear Filters
Clear Filters

how to convert 2 double number and packed in 32 bit

22 views (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 21 Aug 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 on 24 Aug 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

Sign in to comment.

Answers (1)

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

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!