Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Binary representation of stored integer of fi object

Asked by Charles Jackel

Charles Jackel (view profile)

on 18 Mar 2013

I am using a lookup table with values ranging from 0 to pi/4.

These values are all less than one, i.e. 0 to .7854.

I am using the bin function to get the eight MSBs of a 16 bit number.

I noticed that bin(fi(.5000,0,16)) = 1000 0000 0000 0000 but bin(fi(.4555, 0, 16)) = 1110 1001 0011 0111

with bin(fi(.2500,0,16)) = 1000 0000 0000 0000.

Why do .5 and .25 have the same binary representation? Why does .4555 have a larger sized binary representation?

0 Comments

Charles Jackel

Charles Jackel (view profile)

Tags

Products

No products are associated with this question.

2 Answers

Answer by Titus Edelhofer

Titus Edelhofer (view profile)

on 18 Mar 2013
Accepted answer

Hi,

if you only specify the word length and not the fraction length you get two different objects:

>> fi(0.25, 0, 16)
ans = 
  0.2500
          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 16
        FractionLength: 17
>> fi(0.5, 0, 16)
ans = 
    0.5000
          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 16
        FractionLength: 16

Note the difference on the FractionLength.

Now if you want to have numbers between 0 and 1, so FractionLength 16, you get what I think you are looking for:

>> bin(fi(0.5, 0, 16, 16))
ans =
1000000000000000
>> bin(fi(0.25, 0, 16, 16))
ans =
0100000000000000

Titus

0 Comments

Titus Edelhofer

Titus Edelhofer (view profile)

Answer by Charles Jackel

Charles Jackel (view profile)

on 18 Mar 2013

Thank you! That helped a lot!

0 Comments

Charles Jackel

Charles Jackel (view profile)

Contact us