How do I display the binary value of a fixed-point FI object with the radix point in the right place, in Fixed-Point Toolbox 3.3 (R2011a)?

45 views (last 30 days)
I have created a fixed-point object with a specified value, word length, and fraction length using the FI command. I would like to display the fixed-point number in binary form with the radix point in the right place, such that all the numbers to the right of the decimal point correspond to the fractional part of the number.
For example, if the binary value is 1100100100010000, with a word length of 16 and a fraction length of 14, I would like to display it as the following:
11.00100100010000
How do I do this in Fixed-Point Toolbox 3.3 (R2011a)?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Jan 2013
The fixed-point object has several properties that can be used to accomplish this task: 'bin', which provides the binary representation of the number as a string, 'WordLength', provides the word length, and 'FractionLength', which provides the fraction length.
By using some string operations, you can format a string such that the radix point appears in the right place. Please see the code below for an example of how to do this.
clear;
clc;
v = pi;
s = 0;
w = 16;
f = 14;
foo = fi(v,s,w,f);
rawstr = foo.bin;
pointIndex = foo.WordLength - foo.FractionLength;
str1 = rawstr(1:pointIndex);
str2 = '.';
str3 = rawstr(pointIndex+1:end);
outstr = [str1 str2 str3];
disp(foo.bin)
disp(outstr)

More Answers (0)

Tags

Products


Release

R2011a

Community Treasure Hunt

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

Start Hunting!