Troubles with I2C_Write


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Aug 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    For those of you wondering, this algorithm gives decently accurate 10-bit ratios with a Big O of (n^2). I hope some one finds it useful.
    Bear in mind that the Numerator MUST be smaller than the Denominator, and that the denominator bit-shifted left to be bigger than the Power of 2 you're trying to fit it in. Therefore, don't change the 1024 to 16384 and expect it to work (while still using 16-bit WORDs).

    Code:
    TenBitRatio:
    		Result=0
    		while Denominator<1024 
    			Numerator=Numerator<<1
    			Denominator=Denominator<<1
    		WEND
    		while	Denominator>0
    			Digit=0
    			while	Numerator>Denominator
    				Numerator	=	Numerator	-	Denominator
    				Digit=Digit+1
    			WEND
    			Denominator	=	Denominator>>1
    			Result	=	Result	<<	1
    			Result	=	Result	+	Digit
    		WEND
    Last edited by The Altruist; - 23rd March 2010 at 23:59.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts