Searching \ for '[PIC]: fixed point binary representation' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'fixed point binary representation'.

Exact match. Not showing close matches.
'[PIC]: fixed point binary representation'
2001\03\15@031148 by

Hi there,
3.578(dec) = 11.1001 0011 1111 0111 1100 ...(bin)
sorry for bothering you with such stick, but searching at piclist
I found only theory which I can't match to above example.
Thank's again,
Vasile

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

The binary number after the decimal point is a always represents a fraction
of 1.

For a 20bit accurate representation of 0.578 just multiply 0.578 * 2^20
(that's 2 raised to the power of 20) = 606076.928 which truncated and
converted to binary gives you 1001 0011 1111 0111 1100.

For a 10bit accurate result 0.578 * 2^10 = 591.872 which truncated in binary
is 1001 0011 11

So hopefully you see that ANY fraction can be represented by a number of
bits (N) in a binary word so long as you (and you code) understand that 2^N
= 1

Does that help?

Pete

> {Original Message removed}
Pete, it helps more than you imagine! Finaly I've undestand this brilliant
but un-exemplified theory:

A number in binary form is represented by a sum of powers of two:

31        30            0
N      = I  * 2  + I  * 2  + ... I  * 2  +
Q32.32   31        30            0

-1        -2            -32
+ F  * 2  + F  * 2  + ... F  * 2
31        30            0

But what you have written this correct?

> For a 10bit accurate result 0.578 * 2^10 = 591.872 which truncated in
binary
> is 1001 0011 11

seems it depends of justifying, so will be: 0010 0100 1111 , isn't it ?

Thank's, Vasile

On Thu, 15 Mar 2001, Peter Betts wrote:

{Quote hidden}

> > {Original Message removed}
> > For a 10bit accurate result 0.578 * 2^10 = 591.872 which
> > truncated in binary is 1001 0011 11

> seems it depends of justifying, so will be: 0010 0100 1111 ,
> isn't it ?

Err? No. I don't think so it is still XX.1001 0011 11

.1001 0011 11 can be expressed as

(2^-1) + (2^-4) + (2^-7) + (2^-8) + (2^-9) + (2^-10)

{as negative index bits -1,-4,-7,-8,-9 and -10 are set}

If you calculate
(2^-1) + (2^-4) + (2^-7) + (2^-8) + (2^-9) + (2^-10) = 0.5771

Which for a 10bit result is as close to 0.578 as you can get.

Using more bits in the fraction will give you greater accuracy and you will
tend towards your ideal of 0.578 with decreasing error.

Pete

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

Thank's very much !
Vasile

On Thu, 15 Mar 2001, Peter Betts wrote:

{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

fractions are expressed in binary. I will begin with something
you are hopefully already familiar with, which is straight
binary integer representation. I will then extend the
example to include fractional representation as well.

10000000 = 128
01000000 = 64
00100000 = 32
00010000 = 16
00001000 = 8
00000100 = 4
00000010 = 2
00000001 = 1

.10000000 = 1/2   (128/256) .5
.01000000 = 1/4   (64/256)  .25
.00100000 = 1/8   (32/256)  .125
.00010000 = 1/16  (16/256)  .0625
.00001000 = 1/32  (8/256)   .03125
.00000100 = 1/64  (4/256)   .015625
.00000010 = 1/128 (2/256)   .0078125
.00000001 = 1/256 (1/256)   .00390625

Now let's decode 11.10010011
Since 11. = 3 we know the number is 3.something
To determine the "something" fractional part,
consider the fraction to be
(128+16+2+1)/256 = 147/256 = .57421875
maximum error is 1/256 = .00390625
so the truncated 8 bit fraction will have an actual
value somewhere between . 57421875 and .578125
which is an error of .7%

*********
Here is a shortcut way to convert 3.578 to binary:
first write the 3 as 11b
multiply .578*256 and you get 147.968
convert 147 to binary and you get 10010011b
combine the whole number and fraction parts to get
11.10010011b

If you need more digits, convert the .968 remainder
the same way: .988*256=247.808
247 converts to 128+64+32+16+4+2+1 = 11110111
11.10010011 111101111

Need even more digits? Convert the .808 remainder
the same way: .808*256=206.848
206 converts to 128+64+8+4+2 = 11001110
11.10010011 11110111 11001110 etc.

I hope this helps.

Fr. Tom McGahee

{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...