The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
Base Conversion
05-12-2016, 06:46 AM (This post was last modified: 05-12-2016 09:14 AM by Stevetuc.)
Post: #1
Base Conversion
This program will convert between any base, with the user being prompted for the required output base.
It uses B→R() to first convert any base to decimal, then R→B() to convert to desired base:
Code:
EXPORT Baseconv(a)
BEGIN
LOCAL b;
CHOOSE(b, "Base", "System", "Binary","Octal","Decimal","Hex");
R→B(B→R(a),32,b-1)
END;
I find it convenient to access via the Toolbox and User soft key.
I have hardcoded bits as 32. This could be set via another choose() or passed as Fn parameter.

If you prefer to access via a user key, it can be done like this:
Code:
KEY K_3()
BEGIN
"Baseconv()";
END;
I use key 3 because the shift # acts as mnemonic for Base.
Either method will work with rpn mode , so long as the input is already on the stack.

EDIT: replace 32 in R→B(B→R(a),32,b-1) with GETBITS(#) to use the current system setting for integer size

Steve
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Base Conversion - Stevetuc - 05-12-2016 06:46 AM
RE: Base Conversion - jrozsas - 05-12-2016, 09:21 AM
RE: Base Conversion - salvomic - 05-12-2016, 09:55 AM
RE: Base Conversion - jrozsas - 05-12-2016, 01:10 PM
RE: Base Conversion - salvomic - 05-12-2016, 01:13 PM
RE: Base Conversion - Stevetuc - 05-12-2016, 02:11 PM
RE: Base Conversion - salvomic - 05-12-2016, 02:27 PM
RE: Base Conversion - Stevetuc - 05-12-2016, 04:42 PM
RE: Base Conversion - salvomic - 05-12-2016, 04:52 PM
RE: Base Conversion - Stevetuc - 05-12-2016, 06:49 PM
RE: Base Conversion - salvomic - 05-12-2016, 07:12 PM
RE: Base Conversion - Stevetuc - 05-12-2016, 07:26 PM
RE: Base Conversion - salvomic - 05-12-2016, 07:31 PM
RE: Base Conversion - Eddie W. Shore - 06-07-2016, 01:08 PM
RE: Base Conversion - Stevetuc - 06-09-2016, 03:22 PM
RE: Base Conversion - salvomic - 06-09-2016, 03:33 PM
RE: Base Conversion - Stevetuc - 06-10-2016, 09:19 AM
RE: Base Conversion - JDW - 08-16-2018, 03:56 AM
RE: Base Conversion - Tyann - 08-16-2018, 05:36 AM
RE: Base Conversion - JDW - 08-16-2018, 10:02 AM
RE: Base Conversion - Stevetuc - 08-16-2018, 11:21 AM
RE: Base Conversion - JDW - 08-16-2018, 11:43 AM
RE: Base Conversion - Stevetuc - 08-16-2018, 12:19 PM
RE: Base Conversion - JDW - 08-17-2018, 01:46 AM
RE: Base Conversion - Stevetuc - 08-17-2018, 04:13 AM
RE: Base Conversion - salvomic - 06-10-2016, 09:51 AM
RE: Base Conversion - Stevetuc - 06-11-2016, 07:53 AM



User(s) browsing this thread: 2 Guest(s)