Hey Guys, I was making a decimal to binary converter for the TI-84 Plus CE, and so far it was working perfectly(I think) but when I input 48 I get a bad answer(102000), could anybody help me figure out what is wrong
here's the code(I did not yet learn how to create an empty list so I just started with 0, and there might be some bad programming sorry:( )
--------------------------------------
Prompt N
0→S
{0}→L₁
Repeat N=0
(log(N)/log(2))→L
int(L)→F
augment(L₁,{F+1})→L₁
(N-(2^F))→N
End
Disp L₁
For(A,2,dim(L₁),1)
(10^(L₁(A)-1)+S)→S
End
Disp S
----------------------------------------
Formatting for original code for readability:

Code:
```Prompt N 0→S {0}→L₁ Repeat N=0 (log(N)/log(2))→L :If 0: This variable doesn't seem to be used anywhere except in the next line int(L)→F augment(L₁,{F+1})→L₁ (N-(2^F))→N End Disp L₁ For(A,2,dim(L₁),1) (10^(L₁(A)-1)+S)→S End Disp S```

First, some cleanup and optimization (any bugs are still here, just making them easier to find):

Code:
```Prompt N 0→S {0→L₁ Repeat not(N int(log(N)/log(2→F augment(L₁,{Ans+1→L₁ N-2^F→N End Disp L₁ S For(A,2,dim(L₁ Ans+10^(L₁(A)-1 End Ans→S Disp S```

On my own calculator, I modified it slightly and am searching for numbers that give it trouble. Here's my list so far:
Good:15:{0,4,3,2,1}: 1111
Bad:16:{0,4,4}: 2000 (should be 1 0000, and list should be {0,5})
Good:17:{0,5,1}: 1 001
...
Bad:48:{0,6,4,4}: 10 2000 (should be 11 0000, and list should be {0,6,5})
...
Bad:80:{0,7,4,4}: 1002 0000 (should be 101 0000, and list should be {0,7,5})
...112:{0,7,4,4}: 1102 0000 (should be 111 0000, and list should be {0,7,6,5})

From these tests it appears the problem has something to do with it wanting to have two 4s at the end when it should be a single 5. I'll be back when I find a solution.

Edit: It appears to be a rounding error on the calculator's part. Although it gives logBASE(16,2) to be 4, as is correct, for some reason, int(logBASE(16,2)) results in 3.
Hello and welcome to Cemetech! I believe that you should be using round(L)->F rather than int(L)->F. Credits to ReGuess for figuring it out Code:
`2fPart(.5int(N2^seq(X,X,~int(logBASE(N,2)),0`

Input: N = decimal
Output: Ans = X-bit binary (as many bits as it needs)
The output will be a list variable though...
If you want it to be a numerical variable, you can add this line:

Code:
`sum(seq(2^(abs(A-dim(Ans)))Ans(A),A,dim(Ans),1,-1→S`

The first routine is one I posted a while ago here. The second one simply takes the output of the first routine and converts it to a single number, rather than a list of 1s and 0s. There is surely a better/more optimized way to do this, but I think these two lines are pretty good and should be alright for most uses.
ReGuess, MateoConLechuga, and mr womp womp thank you
I really liked the cleaner version of the code thanks
MateoConLechuga wrote:
Hello and welcome to Cemetech! I believe that you should be using round(L)->F rather than int(L)->F. Credits to ReGuess for figuring it out Make that

Code:
`int(round(L→F`
(or in my modification)
Code:
`int(round(log(N)/log(2→F`

The int(stuff) is an important part of the code. round(L) fixes the rounding error so that int( will work.

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum