convert fixed point to real data
조회 수: 63 (최근 30일)
이전 댓글 표시
Hi, I use the command sfi to convert real values into fixed point representation. Specifically, I use this:
F=sfi(my_value, 32, 16);
A=F.hex;
Now, I need to do the opposite. Convert the fixed point to real value. Any ideas? Is there a command for that?
댓글 수: 0
답변 (4개)
Massimo Zanetti
2017년 3월 15일
Does this help you?
%get sfi
a = sfi(pi);
%convert to double
d = double(a)
댓글 수: 2
Massimo Zanetti
2017년 3월 15일
편집: Massimo Zanetti
2017년 3월 15일
Forget about the double method. Actually, the fi objects have a method to get the real world value:
a = sfi(pi)
%real world value
a.data
ans =
3.1416
If you are not dealing with fi objects and your task is to convert a hex number to decimal, then you would use hex2dec Matlab function.
Note: The hex property does not represent the conversion of your real world value to hex base, here is an example:
%store 5 as signed fixed-point with 8bit word and best fraction
a = sfi(5,8);
a.data
5
a.bin
01010000
a.int
80
a.hex
50
As you can see, the numeric values you get are obtained by converting the binary representation of the fixed point number into int, hex, etc.
John D'Errico
2017년 3월 15일
편집: John D'Errico
2017년 3월 15일
In general, whenever you want to convert a numeric value in some other class into a double precision number, you use the function double. This is said without even looking to see if double is defined for that toolbox (I don't have that TB.) I am sure that it is, but I'll check online. Checked.
Use double. Just remember: If you want to make it a double, then double will do it. Similarly, single will convert to a single precision number.
For those who might misinterpret my comment to think that double('1234') should also do that conversion, it is the one case I can think of where you need a different tool. There, you would use str2double.
댓글 수: 0
Erik Aderstedt
2018년 3월 16일
Use storedInteger:
F=sfi(my_value, 32, 16);
value = storedInteger(F);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!