Author |
Message |
|
tiuser1010
Member
Joined: 23 Apr 2009 Posts: 100
|
Posted: 15 Jul 2009 01:21:25 pm Post subject: |
|
|
Ok i've made this routine in basic to convert a binary number stored in Str4 and output a hex number stored in Str1 the length of the binary number is stored in V. Here the code
Code:
:0→L
:10→A
:11→B
:12→C
:13→D
:14→E
:15→F
:"0123456789ABCDEF"→Str0
:"]"→Str1
:Repeat V=1
:For(K,0,3
:expr(sub(Str4,V,1→P
:If P≠0 and K≠0
:2P[sup]K[/sup]→L
:L+M→M
:0→L
:V-1→V
:End
:M→Z
:0→M
:For(W,1,16
:expr(sub(Str0,W,1→R
:If R=Z:Then
:sub(Str0,W,1→Str2
:Str2+Str1→Str1
:Emd:End:End
Now i am not to sure why this code won't work please help
Last edited by Guest on 15 Jul 2009 02:06:23 pm; edited 1 time in total |
|
Back to top |
|
|
ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555
|
Posted: 15 Jul 2009 01:42:00 pm Post subject: |
|
|
I think you forgot to set L to a value at the begining of the program. (If P=0 and K=0 L will not be set.)
Last edited by Guest on 15 Jul 2009 01:46:18 pm; edited 1 time in total |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 15 Jul 2009 01:49:25 pm Post subject: |
|
|
...is there any point to expr(sub(Str0,W,1→R? It seems an unnecessarily complicated way of computing W-1→R. Come to think of it, that entire For( loop can be replaced by sub(Str0,Z+1,1)+Str1→Str1.
Last edited by Guest on 05 Jul 2010 08:23:27 am; edited 1 time in total |
|
Back to top |
|
|
tiuser1010
Member
Joined: 23 Apr 2009 Posts: 100
|
Posted: 15 Jul 2009 01:57:39 pm Post subject: |
|
|
Quote: ...is there any point to expr(sub(Str0,W,1→R? It seems an unnecessarily complicated way of computing W-1→R. Come to think of it, that entire For( loop can be replaced by sub(Str0,Z+1,1)+Str1→Str1.
Hmm... that's a good idea i didn't even think of that
Quote: I think you forgot to set L to a value at the begining of the program. (If P=0 and K=0 L will not be set.)
L doesn't have to be set because when the program get to 2PK→L whatevers in L will be overwriten by that |
|
Back to top |
|
|
ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555
|
Posted: 15 Jul 2009 02:01:12 pm Post subject: |
|
|
ztrumpet wrote: (If P=0 and K=0 L will not be set.)
The first time P might equal 0 and K equals 0, therefore L is not set. |
|
Back to top |
|
|
tiuser1010
Member
Joined: 23 Apr 2009 Posts: 100
|
Posted: 15 Jul 2009 02:05:43 pm Post subject: |
|
|
Ok see what yo are saying i'll change it
Edit:
I made the changes and nothing changed
here's the code
:0→L:
:10→A
:11→B
:12→C
:13→D
:14→E
:15→F
:"0123456789ABCDEF"→Str0
:"]"→Str1:Repeat V=1
:For(K,0,3:expr(sub(Str4,V,1→P
:If P≠0 and K≠0
:2PK→L
:L+M→M
:0→L
:V-1→V
:End
:M→Z
:0→M
:sub(Str0,Z+1,1)+Str1→Str1
:End
Last edited by Guest on 15 Jul 2009 02:20:06 pm; edited 1 time in total |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 15 Jul 2009 02:51:17 pm Post subject: |
|
|
Two mistakes: that should be P2^K→L (you don't really need the If statement either), and you didn't initialize M either.
Last edited by Guest on 05 Jul 2010 08:23:09 am; edited 1 time in total |
|
Back to top |
|
|
tiuser1010
Member
Joined: 23 Apr 2009 Posts: 100
|
Posted: 15 Jul 2009 03:06:13 pm Post subject: |
|
|
There also another problem everytime i run it at the end of the program(i think) the calc says SYNTAX and if i press GOTO it takes me back to the home screen |
|
Back to top |
|
|
ztrumpet
Active Member
Joined: 06 May 2009 Posts: 555
|
Posted: 15 Jul 2009 04:00:17 pm Post subject: |
|
|
That's an expr( error probably. |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 15 Jul 2009 07:12:41 pm Post subject: |
|
|
It works for me so, um, check your input (in particular, that Str4 doesn't have contain any characters other than 0 and 1).
Also, Repeat V=0 would be a better choice than Repeat V=1. |
|
Back to top |
|
|
tiuser1010
Member
Joined: 23 Apr 2009 Posts: 100
|
Posted: 16 Jul 2009 07:01:00 am Post subject: |
|
|
Quote: It works for me so, um, check your input (in particular, that Str4 doesn't have contain any characters other than 0 and 1).
Also, Repeat V=0 would be a better choice than Repeat V=1.
l've tried Repeat V=0 and when V=0 the calc changes this "expr(sub(Str4,V,1→P" to this "expr(sub(Str4,0,1→P" and then the calc will bring up the error DOMAIN |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 16 Jul 2009 09:40:56 am Post subject: |
|
|
Yes, well, Repeat V=0 is supposed to exit the loop if V ever equals 0, so that wouldn't happen.
Of course, it still might happen for a different reason. The condition on the Repeat is only checked every four cycles due to the For( loop. So if V were, say, 2 at some point in the Repeat loop, it would get decreased all the way to 0 inside the For( loop, which goes for four cycles no matter what, and then throw the same error.
In this case, Repeat V=0 is still better because it lets the program work correctly in the case where the number of bits is a multiple of 4 (with Repeat V=1, it works correctly when the number of bits is 4n+1, and ignores the top bit even then). To make the program work in every possible situation, you have to modify the For( loop, or replace it with something else. |
|
Back to top |
|
|
|