BODH - a number converter

Use this section to showcase your programming examples. Or to ask members for programming suggestions
Post Reply
Cosi
Posts: 4
Joined: Thu Jan 19, 2023 5:23 pm
Location: Poland

BODH - a number converter

Post by Cosi »

(I'm not sure if I'm posting this in the correct section, please move my post if there's a more suitable category.)

"Scratching my own itch", I've written a handy number converter for the Organiser. The original version converts numbers between the most commonly used numeral systems: decimal (Dec), hexadecimal (Hex), binary (Bin), and octal (Oct), but by adding literally two lines to the source code (and modifying two other lines), you can add support for any other system.
Due to OPL's technical limitations, only numbers between 0 and 32767 (dec) can be converted.

Source and a pack image:
https://github.com/cosi1/BODH

There's also a new version of my game Psi2048 available:
https://github.com/cosi1/psi2048
Daren
Posts: 42
Joined: Tue Jan 03, 2023 10:03 pm

Re: BODH - a number converter

Post by Daren »

Just in case you were unaware you can post code directly into the forum post, it makes seeing your code easier than going to an external link. To post code just use the 5 icon above the reply box with the “</>” button, then paste the code in.
Cosi
Posts: 4
Joined: Thu Jan 19, 2023 5:23 pm
Location: Poland

Re: BODH - a number converter

Post by Cosi »

Thanks for the heads up, Daren. When I come up with something shorter, I'll definitely use this feature :-)
MartinP
Posts: 45
Joined: Wed Jan 04, 2023 7:51 pm

Re: BODH - a number converter

Post by MartinP »

Thanks for posting this, I've been using it to convert some values. Interesting too, to see how it works. I made a few mods for ease of use and to allow bigger numbers, and I also split binary into groups of 4 digits to read them more easily. I forked your github repositry: https://github.com/martinprest/BODH2
On Jaap's website, he has a hex calculator, but it doesn't do binary. I haven't found a use for octal yet, but I guess there must be some, anyway without octal the program name would be BDH, which doesn't have such a nice sound to it.
I feel I should also mention the OPL command HEX$, which only works for converting base 10 to 16.
I also recently rediscovered that in OPL you can put a '$' in front of a number to enter it in hex e.g. $FF = 255, this can be done in CALC also. It doesn't seem to be described much in the Organiser manual, just given in some code examples that use POKE or PEEK.
Martin P.
Cosi
Posts: 4
Joined: Thu Jan 19, 2023 5:23 pm
Location: Poland

Re: BODH - a number converter

Post by Cosi »

Thanks, Martin! (Also, apologies for the late response.)

Regarding octal conversions, the most obvious use case is Unix file permissions; I don't really use octal that much, but:
without octal the program name would be BDH, which doesn't have such a nice sound to it.
:D
Post Reply