HP Forums
50G custom units conversions - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: 50G custom units conversions (/thread-2085.html)



50G custom units conversions - CosmicTruth - 09-06-2014 01:29 AM

Has anyone done any coding to mimic the G series units and units conversions? I'd like to make something to convert some custom units not in the 50G units menu and a pick list is going to be too clunky.
if anyone has any pointers or code I'd appreciate it.


RE: 50G custom units conversions - rkf - 09-06-2014 07:17 PM

It's done absolutely the same way as for the 48G series, and should be well documented either in the users reference manual, or the advanced users reference manual. I have done via custom menu conversions between various European ex-currencies, when the Euro was introduced, and later added conversion for currencies from the Harry Potter universe to the same custom menu.

Unfortunately, I don't have the according materials at my hands now. If nobody else answers until Monday (when I'm at work again), I will post an example.

Kind regards, Ralf.


RE: 50G custom units conversions - CosmicTruth - 09-07-2014 02:02 AM

Thanks rkf, lets see what you've done, i made this but I don't like the way the conversion is left on the stack after some conversions.
please help me with any ideas or code examples ect ect
also I didn't know what to call this, i put it in its own directory and call it ...
'CONV'
Code:
%%HP: T(3)A(D)F(.);
\<< { { "Bit" {
  \<< "Bit" \->TAG DUP 1048576 / 'MBI' STO
  \>>
  \<< MBI 1048576 * "Bit" \->TAG
  \>> } } { "Byte" {
  \<< "Byte" \->TAG DUP 131072 / 'MBI' STO
  \>>
  \<< MBI 131072 * "Byte" \->TAG
  \>> } } { "KBit" {
  \<< "KBit" \->TAG DUP 1024 / 'MBI' STO
  \>>
  \<< MBI 1024 * "KBit" \->TAG
  \>> } } { "KByte" {
  \<< "KByte" \->TAG DUP 128 / 'MBI' STO
  \>>
  \<< MBI 128 * "KByte" \->TAG
  \>> } } { "MBit" {
  \<< "MBit" \->TAG DUP 1 / 'MBI' STO
  \>>
  \<< MBI 1 * "MBit" \->TAG
  \>> } } { "MByte" {
  \<< "MByte" \->TAG DUP .125 / 'MBI' STO
  \>>
  \<< MBI .125 * "MByte" \->TAG
  \>> } } { "GBit" {
  \<< "GBit" \->TAG DUP .0009765625 / 'MBI' STO
  \>>
  \<< MBI .0009765625 * "GBit" \->TAG
  \>> } } { "GByte" {
  \<< "GByte" \->TAG DUP 1.220703125E-4 / 'MBI' STO
  \>>
  \<< MBI 1.220703125E-4 * "GByte" \->TAG
  \>> } } { "TerByte" {
  \<< "TerByte" \->TAG DUP 1.19209289551E-7 / 'MBI' STO
  \>>
  \<< MBI 1.19209289551E-7 * "TerByte" \->TAG
  \>> } } { "PetByte" {
  \<< "PetByte" \->TAG DUP 1.16415321827E-10 / 'MBI' STO
  \>>
  \<< MBI 1.16415321827E-10 * "PetByte" \->TAG
  \>> } } } MENU
\>>

this is untested but is intended to convert between units using the softkey menu,
enter a number and hit the softkey for the type of unit, then the left shift key and the unit you want to convert to. This converts between computer storage units and might be useful once completed.
thanks for any input..


RE: 50G custom units conversions - rkf - 09-08-2014 08:36 AM

(09-06-2014 07:17 PM)rkf Wrote:  It's done absolutely the same way as for the 48G series, and should be well documented either in the users reference manual, or the advanced users reference manual. ...

I was right, it's very good documented in the "HP 48G Series User's Guide", a scanned copy of which may be found here.

Have a look at page 10-14 (page 132 in the scanned PDF) "Creating User-Defined Units", and further page 25-15 (page 361 in the scanned PDF) "User-Defined Units", where the use with help of a custom menu is explained. Although written for the 48G, it works out-of-the-box for the 49G, and 50g, too.

Hope that helps!

Kind regards,
Ralf.


RE: 50G custom units conversions - CosmicTruth - 09-08-2014 11:40 PM

Well documented yes, can I understand it NO. one thing HP never did was have a smart guy (like you) explain it to a dumb guy (like me) until I could teach it to someone else. I tried the examples in them books but all i got was "CONVERT Error Invalid Unit"! so can you show me a little code to just change between 2 units using custom units? The examples in all the HP manuals are un-understandable to me.

The section on Unit prefixes also looks invaluable to me where You can enter prefixes for units according to the table of prefixes from the SI system. I dont understand that either, but I'll wait on that one till i get my current quest solved.

On a lighter note i just got a HP 10B for $1.95 at a second hand shop, all I had to do is add batteries Smile

Well thanks for all your help and any help you are about to reveal to me, and if you don't have a custom units code example I will still figure this out on my own in a couple weeks, or months, or next year... maybe. ((Smile))


RE: 50G custom units conversions - rkf - 09-09-2014 06:49 AM

(09-08-2014 11:40 PM)CosmicTruth Wrote:  ... so can you show me a little code to just change between 2 units using custom units? ...

I will try my very best! Let's take the money conversion from the Harry Potter universe: The wizards use a strange system of Galleons, Sickles, and Knuts, whereas

1 Galleon = 17 Sickles
1 Sickle = 29 Knuts (thus 1 Galleon = 493 Knuts)

BTW, the relation to the "real" world is given by 1 Galleon ~ £5, thus 1 Knut ~ 1 Penny.

You would implement this as follows:

Start with a new directory, e.g. Potter, and change into it via keypress of the according softkey in the vars menu:

'Potter' CRDIR Potter

Now define the new units creating variables with appropriate name, and value. Lets start with Knuts, which we define via Sickles, knowing that one Knut is 1/29 Sickle:

'3.44827586207E-2_Sickles' 'Knuts' STO>

Next for Sickles, defined as 1/17 Galleon:

'5.88235294118E-2_Galleons' 'Sickles' STO>

And for the conversion to real world:

'5.0_£' 'Galleons' STO>

But finally you have to declare the "basic" unit within this system, otherwise you will get an "Invalid Unit" error. I choose the GBP. This is accomplished the following way:

'1_?' '£' STO>

It's clear that there may be one and only one basic unit defined. Therefore you need for every unit system it's own directory!

To start the conversions, you need finally a special custom menu:

{ '1_Knuts' '1_Sickles' '1_Galleons' '1_£' } 'CST' STO>

And now simply call CUSTOM (left-shift MODE key). After that, you convert the usual way via softkey and left-shift-softkey, e.g.

Enter 10 softkey '£', you will have 10_£ on the stack.

left-shift softkey Galleons will give 2_Galleons on the stack.

left-shift softkey Sickles will give 34_Sickles on the stack.

How much is 2 Galleons 4 Sickles 11 Knuts? I omit the word softkey:

2 Galleons 4 Sickles + 11 Knuts + ends up in 1113._Knuts

left-shift £ gives ~ 11.29_£

BTW, we see the big advantage of the decimal system. SI prefixes may simply added when needed. So you may key in e.g. 1000 kilo-Knuts:

1000._kKnuts

which converts via left-shift £ to ~ 10142_£

Hope that helps,
Ralf.


RE: 50G custom units conversions - CosmicTruth - 09-11-2014 12:43 AM

Thank you so much this works where my attempts to follow the manuals failed.


RE: 50G custom units conversions - CosmicTruth - 09-17-2014 11:36 AM

This is what I put together for computer storage units conversion:

'Bit'
Code:
%%HP: T(3)A(D)F(.);
1_?

'Byte'
Code:
%%HP: T(3)A(D)F(.);
8_Bit

'KBit'
Code:
%%HP: T(3)A(D)F(.);
128_Byte

'KByte'
Code:
%%HP: T(3)A(D)F(.);
8_KBit

'MBit'
Code:
%%HP: T(3)A(D)F(.);
128_KByte

'MByte'
Code:
%%HP: T(3)A(D)F(.);
8_MBit

'GBit'
Code:
%%HP: T(3)A(D)F(.);
128_MByte

'GByte'
Code:
%%HP: T(3)A(D)F(.);
8_GBit

'TByte'
Code:
%%HP: T(3)A(D)F(.);
1024._GByte

'PByte'
Code:
%%HP: T(3)A(D)F(.);
1024._TByte

'CST'
Code:
%%HP: T(3)A(D)F(.);
{ '1_Bit' '1_Byte' '1_KBit' '1_KByte' '1_MBit' '1_MByte' '1_GBit' '1_GByte' '1_TByte' '1_PByte' }

so the directory will look like this:

Code:
%%HP: T(3)A(D)F(.);
DIR
  KBit '128_Byte'
  Bit '1_?'
  Byte '8_Bit'
  KByte '8_KBit'
  MBit '128_KByte'
  MByte '8_MBit'
  GBit '128_MByte'
  GByte '8_GBit'
  TByte '1024._GByte'
  PByte '1024._TByte'
  CST { '1_Bit' '1_Byte' '1_KBit' '1_KByte' '1_MBit' '1_MByte' '1_GBit' '1_GByte' '1_TByte' '1_PByte' }
END

is this all possible using the unit prefixes?


RE: 50G custom units conversions - rkf - 09-17-2014 11:57 AM

(09-17-2014 11:36 AM)CosmicTruth Wrote:  ... is this all possible using the unit prefixes?

Seems OK to me, simply try it out! I have nearly the same directory on my HP50g, I only omitted the bit-stuff with the exception of the bit himself, and also the "it" in the corresponding unit names.

I just testet regarding the SI-prefixes. When I enter with activated custom menu

1 _ k bit (key 1, key underscore, softkey bit)

and then press left-shift softkey kB (for converting to kByte), I get the result

.1220703125_kB

which is correct, since 1kbit = 1000 bit (SI prefix kilo = 1000), and 1 kByte = 1024 Byte = 8192 bit, thus the resulting number should be 1000/8192=0.1220703125, meaning all is perfect!

Kind regards, Ralf.