From: José María on
Hi,

I have a signed fixed point number N1 with 11 bits wordlength 9 fraction bits, and I need to truncate N1 to obtain a signed fixed point number N2 with 8 bits wordlength 6 fraction bits, it is, N2 is N1 but without the 3 LSB bits, here an example:

N1 =

-0.0020

DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 11
FractionLength: 9

RoundMode: round
OverflowMode: saturate
ProductMode: FullPrecision
MaxProductWordLength: 128
SumMode: FullPrecision
MaxSumWordLength: 128
CastBeforeSum: true

K>> bin(N1)
ans =11111111111

What I need is a signed fixed point number bin(N2)= 11111111, Do you now some function ??? it is a truncation but in bits level...

Thanks !!!!!
From: Ashok Charry on
Hi Jose,

If you set the 'RoundMode' of the fi object N2 to 'Floor' you will get
what you want:

N1 = fi(-0.0020,1,11,9,'RoundMode','floor');
bin(N1)
% 11111111111
N2 = fi(0,1,8,6,'RoundMode','floor');
N2(1) = N1;
bin(N2)
% 11111111

Hope that helps.


Ashok Charry
Fixed-Point Engineer.
MathWorks

On 7/27/10 5:17 PM, José María wrote:
> Hi,
> I have a signed fixed point number N1 with 11 bits wordlength 9 fraction
> bits, and I need to truncate N1 to obtain a signed fixed point number N2
> with 8 bits wordlength 6 fraction bits, it is, N2 is N1 but without the
> 3 LSB bits, here an example:
>
> N1 =
>
> -0.0020
>
> DataTypeMode: Fixed-point: binary point scaling
> Signedness: Signed
> WordLength: 11
> FractionLength: 9
>
> RoundMode: round
> OverflowMode: saturate
> ProductMode: FullPrecision
> MaxProductWordLength: 128
> SumMode: FullPrecision
> MaxSumWordLength: 128
> CastBeforeSum: true
>
> K>> bin(N1)
> ans =11111111111
>
> What I need is a signed fixed point number bin(N2)= 11111111, Do you now
> some function ??? it is a truncation but in bits level...
>
> Thanks !!!!!

From: José María on
Ashok Charry <acharry(a)mathworks.com> wrote in message <i2nlrg$dtk$1(a)fred.mathworks.com>...
> Hi Jose,
>
> If you set the 'RoundMode' of the fi object N2 to 'Floor' you will get
> what you want:
>
> N1 = fi(-0.0020,1,11,9,'RoundMode','floor');
> bin(N1)
> % 11111111111
> N2 = fi(0,1,8,6,'RoundMode','floor');
> N2(1) = N1;
> bin(N2)
> % 11111111
>
> Hope that helps.
>
>
> Ashok Charry
> Fixed-Point Engineer.
> MathWorks
>
> On 7/27/10 5:17 PM, José María wrote:
> > Hi,
> > I have a signed fixed point number N1 with 11 bits wordlength 9 fraction
> > bits, and I need to truncate N1 to obtain a signed fixed point number N2
> > with 8 bits wordlength 6 fraction bits, it is, N2 is N1 but without the
> > 3 LSB bits, here an example:
> >
> > N1 =
> >
> > -0.0020
> >
> > DataTypeMode: Fixed-point: binary point scaling
> > Signedness: Signed
> > WordLength: 11
> > FractionLength: 9
> >
> > RoundMode: round
> > OverflowMode: saturate
> > ProductMode: FullPrecision
> > MaxProductWordLength: 128
> > SumMode: FullPrecision
> > MaxSumWordLength: 128
> > CastBeforeSum: true
> >
> > K>> bin(N1)
> > ans =11111111111
> >
> > What I need is a signed fixed point number bin(N2)= 11111111, Do you now
> > some function ??? it is a truncation but in bits level...
> >
> > Thanks !!!!!



Ok !!!!! It was the solution, thanks !!!!!!