[6.57] Sum Binary "1" Digits In An Integer - Texas Instruments TI-89 Tip List

Graphing calculator
Hide thumbs Also See for TI-89:
Table of Contents

Advertisement

where
Solve [3B] for n, replace in [4B], and define a new variable c such that
✁x m
c =
✁x s m =
x sb −x sa
then
Replace [6B] in [1B] for
Now, since s
(xs) = s(x), for any given x and its equivalent scaled x
s
the sum and limit, and [7B] becomes
I s = 1 c lim
nd∞
m=1
which, on comparison with [2b], is just
or
We can also express [8B] in terms of the original scaling factor k. The scaling is defined by
x sa = 1
x a − x 2
h
which we can solve for h:
and comparison with [5B] gives
so we have the final desired result:
[6.57] Sum binary '1' digits in an integer
Some applications need to find the number of '1' digits in a binary integer. For example, this sum is
needed to calculate a parity bit. Another example would be a game or a simulation in which positions
are stored as '1' digits in an integer, and you need to find the total number of pieces in all positions.
The following TI Basic function will find the number of 1's in the input argument n.
sum1s(n)
Func
©(n) sum of binary 1's in n, n<2^32
©Must use Exact or Auto mode!
©26april02/dburkett@infinet.com
x b −x a
s ( x ) $ ✁x m
x sb = 1
I = lim
nd∞
m=1
x sb −x sa
✁x s m =
x b −x a
✁x m =
n
✁x m
✁x s m =
c
Is = lim
nd∞
m=1
Is = 1 c $ I
I = c $ I s
x b − x 2
h
x a −x b
h =
x sa −x sb
h = c
I = h $ I s
s ( x ) $ ✁x m
n
✁x m
s s ( x s ) $
c
, we move the 1/c constant outside
s
[2B]
[3B]
[4B]
[5B]
[6B]
[7B]
[8B]
6 - 110

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ti-92+

Table of Contents