Thursday, November 22, 2018

TI 84 Plus: Expressing an Integer as a Sum of Powers of Two

TI 84 Plus:  Expressing an Integer as a Sum of Powers of Two

Happy Thanksgiving!

The program POW2SUM expresses a positive integer as a sum of powers of 2.  The program generates a list of terms.

The powers of 2 are:

2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
 and so on.

Examples:

117 = 1 + 4 + 16 + 32 + 64 (+ 0) 
(117 = 2^0 + 2^2 + 2^4 + 2^6)

386 = 2 + 128 + 256
(386 = 2^1 + 2^7 + 2^8)

Note:  The list includes a 0 (due to programming limitations on the TI-84 Plus). 

TI 84 Plus Program POW2SUM

"EWS 2018-11-18"
Disp "N = 2^P1+2^P2+..."
Prompt N
{0} → L₁
Repeat N≤0
ln(N)/ln(2) → P
iPart(P) → P
N-2^P → N
augment({2^P},L₁) → L₁
End
Pause L₁

(I like Unicode)

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

Spotlight: Akron Brass FireCalc Pocket Computer

Spotlight: Akron Brass FireCalc Pocket Computer Welcome to a special Monday Edition of Eddie’s Math and Calculator blog. Thi...