"Amish Rughoonundon" <axr0284@yahoo.com> wrote in message <i8df95$c8j$1@fred.mathworks.com>...
> Hi,
> I am getting confused with the way matlab computes fixed point.
> I tried to get the fixed point representation of 1.5 two ways
> I understand that for the first one is uses the MSB as the sign bit and then the computation is
> [1*(2^0)]+[0*(1/2^1) ] = 1
>
> I am totally confused how it's calculating the second one. I would expect it to throw an error since it cannot fit the sign bit on top of two fractional bit in a word length of 2.
> Is the word length meaningless. Thanks for any insight.
>
> >> finum=fi(1.5,1,2,1)
> finum = 1
> DataTypeMode: Fixedpoint: binary point scaling
> Signedness: Signed
> WordLength: 2
> FractionLength: 1
> >> finum.bin
> ans =10
>
> >> finum=fi(1.5,1,2,2)
> finum = 0.5000
> DataTypeMode: Fixedpoint: binary point scaling
> Signedness: Signed
> WordLength: 2
> FractionLength: 2
> >> finum.bin
> ans =10
          
You can't accurately represent 1.5 with fixed point format less than word length 3 bits. With fraction length 1, it would be (in twos complement):
1*2^1 + 0*2^0 + 1*2^(1) = 1.5 (bits = 1 0.1)
With fraction length 2, you would need word length of at least 4:
1*2^1 + 0*2^0 + 1*2^(1) + 0*2^(2) = 1.5 (bits = 1 0.1 0)
Read the Wikipedia article at:
http://en.wikipedia.org/wiki/Two's_complement
Roger Stafford
