Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

HELP: Learning Fixed point C coding

Status
Not open for further replies.

josephgopu

Newbie level 5
Joined
Nov 24, 2010
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,360
Hi every body,

I want to learn Fixed point C coding as I'm belongs to Digital signal processing field. Please post any tutorials, materials, links.....which explains Fixed point coding starting from basics.
 

Just use integer variables (short int, int, long int) and do the maths with the usual operations (+-/*)...
 

The idea of fixed point is you have whole number values (integers) and some number of bits on the low end represent the fractional value, and the rest represent the whole number value.

So suppose your numbers are 32 bits. You could have 8 bits fractional part and 23 bits for the whole number amount, and 1 sign bit. In this scenario:

256 = 1
257 = 1 + (1/256)
258 = 1 + (2/256)
...
511 = 1 + (255/256)
512 = 2

Addition and subtraction just work, no special corrections are necessary. But if you multiply two numbers, your result will be 256x too big. So you need to divide by 256, or shift right 8 bits.
A_times_B = A * B / 256;
Divide you do the opposite:
A_dividedby_B = A*256 / B

Problems come up with overflows. It's handy if you're using 32 bit ints to do your math with 64 bit longs to avoid overflows.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top