Decimal --> Octal converter for CASIO BASIC (the CASIO graphic calculators)

Started by Muzer, May 17, 2010, 11:38:13 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Muzer

I got bored during a lesson and wrote this program. If you have a CASIO Graphic calculator that you take around with you it may be useful to convert numbers "in the field". Or something... I wrote it on my own CASIO calculator, which is pretty much the lowest common denominator as far as the programmable ones go, so this should work on pretty much all of them. I have no idea if anyone on here does own such a calculator, but if so, please type this in!

What made this particularly interesting to write is the fact that the only datatype my calculator supports is floats (real numbers) - no strings are used, and if I say so myself, I think I managed it quite neatly!

WHAT WORKS: Positive decimal integer --> Octal conversion
WHAT IS COMING SOON: Non-integer and negative number support
WHAT MIGHT COME: Octal --> Decimal (I'll have to think this one through - it'll probably be harder)

Finally before the program itself, here are the symbols I use in the program and what they are on the calculator (as you probably know, the calculator has some symbols that can't easily be expressed in ASCII, so one must improvise):

-> is the right arrow (the assignment operator), which on my calculator is under "tan" and above "AC/on"
Int/ is the integer division function, represented by the word "Int" followed by a divide sign. On my calculator, it is accessible through the "OPTN" menu. If you find your calculator lacks this, Int(X/3) is a replacement.
Rmdr is the remainder function - if your calculator lacks this, look for "Mod", or use Frac(X/3) as a replacement.
>= is the "greater than or equal to" sign
* is the multiplication sign.
All other words and symbols you should just be able to find on your calculator, possibly through the menus. Owners of even more basic calculators than mine (one of which I used to own) will have to replace while loops with lbl and goto, and If statements with the version that uses =>. If someone wants this, I can write it out, but if not, I won't if you don't mind ;)

So, without further ado:

PROGRAM NAME: DEC2OCT

0->O
"DECIMAL"?->D
0->X
While 2^X<D
X+1->X
WhileEnd
While D>0
10^(X Int/ 3)->M
M*2^(X Rmdr 3)->N
If D-2^X>=0
Then D-2^X->D
O+N->O
IfEnd
X-1->X
WhileEnd
O



If you wish to port this program to another platform, here's the pseudo-code and a few extra notes I wrote on how I was to go about doing it (d represents the decimal number, o the octal) (quite worryingly I wrote it with a BASIC-like syntax - I could lie and say that's probably because the target platform was BASIC, but I'm sure it's a less good reason than that - that I still haven't properly weaned myself off BASIC):

2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 10
2^4 = 20

etc...

* o = 0
* count x up until 2^x > d
* m = 10^(int(x/3))
* n = m * 2^(x mod 3)
* if d - 2 ^ x >= 0 then d = d - 2 ^ x; o += n
* decrement x, go up 3 steps - repeat until d = 0
[21:42:56] <@Muzer> Apple products used to be good, if expensive
[21:42:59] <@Muzer> now they are just expensive

Tsufätu Ayioangä

Um... I have a TI nSpire.  I dunno what calc yer talking about but will this work on mine?

Muzer

I've used TI calculators before, their BASIC is similar to, but not the same as, CASIO BASIC. If you can't or don't want to port it yourself, I'll look for the manual for your calculator online and port it for you.

I'm talking about calculators made by CASIO - maybe they are less common where you live? They're very common here in Britain.
[21:42:56] <@Muzer> Apple products used to be good, if expensive
[21:42:59] <@Muzer> now they are just expensive

eanayo

Ooooohhhh! Programming BASIC during boring lessons brings back so many warm memories. I used to have a Casio PB-700 (same as here) with the portable printer / microcassete recorder. Graphing on that thing was dreadfully slow... my most advanced program on that box was probably a Mastermind clone. Took many boring lessons to get that done, all in gruesome BASIC on that tiny 4-line display with cramp-inducingly small keys. Ah, those were the days ;)

Sadly, it just died one day and was superseded by a TI voyage 200. That had gcc available, so programming was less painful. It also runs 2-player Tetris, which caused a major drop in attention during classes.

But I digress.

Anyway, great job, hope people will find it useful!

edit: Well, the nSpire should be able to do dec<->oct out of the box, so... ;)

Visit Our Dictionary for eBook readers, The Na'vi Word Puzzle Game and the Cryptogram Generator
srake tsun pivlltxe san [ˈɔaχkat͡slʃwɔaf]?

Tsufätu Ayioangä

Yea, I live in Arizona and I've never even heard of a CASIO lol.  Oh well :)

Muzer

OK, I've found the manual - I assume you meant the original nSpire as opposed to the CAS version - no idea what differences there are, but the manual I picked up was the original.

Untested, but it looks as if it should go something like this (make sure you can tell the difference between O and 0 in whatever font you use - O is a letter, 0 is a number). If you don't know where you enter programs, I found this: "To create a program, make sure you are in the Calculator application. Press Menu and go to 8. Then, press 1 and 1 again. A window will pop up prompting the name of the program. Put in the name [in this case dectooct], select the type (program or function [in this case program]) and press OK. Now, you are in the program editor and you can now create your program.":

Define dectooct(d)
Pgrm
0->O
0->X
While 2^X<D
X+1->X
EndWhile
While D>0
10^intDiv(X,3)->M
M*2^mod(X,3)->N
If D-2^X>=0 Then
D-2^X->D
O+N->O
EndIf
X-1->X
EndWhile
Disp O
EndPgrm



To run, type:
dectooct(the-number-to-convert)





If it doesn't work, let me know where it says the error is.



Because your calculator, among other things, supports strings as a datatype, you can probably make this MUCH more efficient - as it is, it's just a direct port of my program.
[21:42:56] <@Muzer> Apple products used to be good, if expensive
[21:42:59] <@Muzer> now they are just expensive

Feiane

In my area people use CASIO if they can't afford TI  ;)

Calculator rivalry!

Click >> fìtsenge << to learn about a na'vi nì'aw game I'm hosting in a week or two. Please join!

Tsufätu Ayioangä

Crap now I have to /find/ my calculator lol

I'll try it when I find it and let you know how it works

`Eylan Ayfalulukanä

Quote from: Aysyal on May 17, 2010, 12:07:35 PM
Ooooohhhh! Programming BASIC during boring lessons brings back so many warm memories. I used to have a Casio PB-700 (same as here) with the portable printer / microcassete recorder. Graphing on that thing was dreadfully slow... my most advanced program on that box was probably a Mastermind clone. Took many boring lessons to get that done, all in gruesome BASIC on that tiny 4-line display with cramp-inducingly small keys. Ah, those were the days ;)

Sadly, it just died one day and was superseded by a TI voyage 200. That had gcc available, so programming was less painful. It also runs 2-player Tetris, which caused a major drop in attention during classes.

But I digress.

Anyway, great job, hope people will find it useful!

edit: Well, the nSpire should be able to do dec<->oct out of the box, so... ;)

Ahhh.... I have a PB700 in good working order. Will have to try this on it. I also have two of the newer Casio programmable calculators. I hope to pick up a TI one of these days....I like the advanced calculators. Like you, they helped me not pay attention during boring lectures...

Yawey ngahu!
pamrel si ro [email protected]

eanayo

Quote from: `Eylan Ayfalulukanä on May 18, 2010, 02:17:50 AM
Ahhh.... I have a PB700 in good working order. Will have to try this on it. I also have two of the newer Casio programmable calculators. I hope to pick up a TI one of these days....I like the advanced calculators. Like you, they helped me not pay attention during boring lectures...
Wow! Take good care of that PB700, would be a shame if it suffered the same fate as mine. It's such a sweet machine (albeit with a whacky BASIC)

As for TI, I really love their m68k based ones with QWERTY keyboard (TI 92, v200). It's just much so easier to do algebra with a proper keyboard (also, the cursor keys are exquisitely placed for playing games). I briefly had a TI-89 Titanium, and it just took me ages to enter stuff. It's a real shame that they don't have nSpires with QWERTY, because otherwise they'd be fairly neat (especially with a bit more power than the ol' m68k ;) )

Also, muzer, your TI BASIC program works perfectly fine on a v200, so it should also run on the nSpire.

Visit Our Dictionary for eBook readers, The Na'vi Word Puzzle Game and the Cryptogram Generator
srake tsun pivlltxe san [ˈɔaχkat͡slʃwɔaf]?