필터 지우기
필터 지우기

how to convert 2 double number and packed in 32 bit

조회 수: 22 (최근 30일)
rps rathore
rps rathore 2015년 8월 21일
댓글: rps rathore 2015년 8월 27일
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