05-12-2016, 06:46 AM
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:
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:
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
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 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;
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