From: Alex on
When I try to get the binary representation of a fixed point variable, it returns nothing, but when I assign it to a temp variable and check the bin of that, it is the correct value. I am not sure why the .bin is not reporting correctly... Any advice?

Thanks!

Here are my settings for the fimath:
fiSettings = fimath('castbeforesum', false, 'OverflowMode', 'saturate','ProductMode', 'KeepMSB', 'SumMode', 'KeepMSB', 'ProductWordLength',32,'SumWordLength',32);

Below is a contextual example:

>> fipsufluxx(cnt)

ans =

-1422

DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 0
>> fipsufluxx.bin(cnt)

ans =



>> x=fipsufluxx(cnt)

x =

-1422

DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 0
>> x.bin

ans =

1111101001110010
From: Ashok Charry on
Alex,

When you call the bin on a fi that is a vector thats going to give you
one long string (single string) of 1's & 0's with empty spaces
in-between to separate one value from the next:

a = fi(rand(1,5));
a.bin

ans =

0011001110110011 0000110001011001 0001000011100101
0111100010010101 0111101001100011

Then depending on what your index "cnt" is you might just end up
getting an ' ' (space) because with the syntax a.bin(cnt) you are really
indexing into the binary string and not into a:

a.bin(17)

ans =

% this is an empty space because the the wordlength is 16 so the 17
% "bin" value is a space to separate the 1st value from the second.

To do what you want to do and in one step this is what you need to type:
% say I want the bin of the 4th value in a:

bin(a(4))
ans =

0111100010010101

Hope this answers your questions and helps you out.


Thanks!

Ashok Charry
The Mathworks


On 3/24/10 10:55 AM, Alex wrote:
> When I try to get the binary representation of a fixed point variable,
> it returns nothing, but when I assign it to a temp variable and check
> the bin of that, it is the correct value. I am not sure why the .bin is
> not reporting correctly... Any advice?
>
> Thanks!
>
> Here are my settings for the fimath:
> fiSettings = fimath('castbeforesum', false, 'OverflowMode',
> 'saturate','ProductMode', 'KeepMSB', 'SumMode', 'KeepMSB',
> 'ProductWordLength',32,'SumWordLength',32);
>
> Below is a contextual example:
>
>>> fipsufluxx(cnt)
>
> ans =
>
> -1422
>
> DataTypeMode: Fixed-point: binary point scaling
> Signedness: Signed
> WordLength: 16
> FractionLength: 0
>>> fipsufluxx.bin(cnt)
>
> ans =
>
>
>
>>> x=fipsufluxx(cnt)
>
> x =
>
> -1422
>
> DataTypeMode: Fixed-point: binary point scaling
> Signedness: Signed
> WordLength: 16
> FractionLength: 0
>>> x.bin
>
> ans =
>
> 1111101001110010

From: Alex on
Ashok, you have saved me again!

I guess that sort of makes sense that .bin is a string... I just wasnt expecting it since int and double work the way I implemented.

Thanks!

Ashok Charry <acharry(a)mathworks.com> wrote in message <hodarb$fsp$3(a)fred.mathworks.com>...
> Alex,
>
> When you call the bin on a fi that is a vector thats going to give you
> one long string (single string) of 1's & 0's with empty spaces
> in-between to separate one value from the next:
>
> a = fi(rand(1,5));
> a.bin
>
> ans =
>
> 0011001110110011 0000110001011001 0001000011100101
> 0111100010010101 0111101001100011
>
> Then depending on what your index "cnt" is you might just end up
> getting an ' ' (space) because with the syntax a.bin(cnt) you are really
> indexing into the binary string and not into a:
>
> a.bin(17)
>
> ans =
>
> % this is an empty space because the the wordlength is 16 so the 17
> % "bin" value is a space to separate the 1st value from the second.
>
> To do what you want to do and in one step this is what you need to type:
> % say I want the bin of the 4th value in a:
>
> bin(a(4))
> ans =
>
> 0111100010010101
>
> Hope this answers your questions and helps you out.
>
>
> Thanks!
>
> Ashok Charry
> The Mathworks
>
>
> On 3/24/10 10:55 AM, Alex wrote:
> > When I try to get the binary representation of a fixed point variable,
> > it returns nothing, but when I assign it to a temp variable and check
> > the bin of that, it is the correct value. I am not sure why the .bin is
> > not reporting correctly... Any advice?
> >
> > Thanks!
> >
> > Here are my settings for the fimath:
> > fiSettings = fimath('castbeforesum', false, 'OverflowMode',
> > 'saturate','ProductMode', 'KeepMSB', 'SumMode', 'KeepMSB',
> > 'ProductWordLength',32,'SumWordLength',32);
> >
> > Below is a contextual example:
> >
> >>> fipsufluxx(cnt)
> >
> > ans =
> >
> > -1422
> >
> > DataTypeMode: Fixed-point: binary point scaling
> > Signedness: Signed
> > WordLength: 16
> > FractionLength: 0
> >>> fipsufluxx.bin(cnt)
> >
> > ans =
> >
> >
> >
> >>> x=fipsufluxx(cnt)
> >
> > x =
> >
> > -1422
> >
> > DataTypeMode: Fixed-point: binary point scaling
> > Signedness: Signed
> > WordLength: 16
> > FractionLength: 0
> >>> x.bin
> >
> > ans =
> >
> > 1111101001110010