Base Conversion
06-10-2016, 09:19 AM (This post was last modified: 03-20-2017 06:57 AM by Stevetuc.)
Post: #17
 Stevetuc Senior Member Posts: 300 Joined: Jan 2014
RE: Base Conversion
One more tweak :-)

Using the alternative command:
SETBITS(SETBASE(in,base-1),bits)
Turns out to be superior since there is no need to detect numbers entered without # , it handles them by default as decimal.
Therefore we can remove this line:
IF LEFT(STRING(in),1) ≠ "#" THEN in:=EXPR("#"+in+"d") END

Code:
EXPORT Baseconv(in) BEGIN LOCAL base,bits,sign; CHOOSE(base, "Base", "System", "Binary","Octal","Decimal","Hex"); CHOOSE(bits, "Size","System","Input","8","16","32","64"); IF bits >2 THEN CHOOSE(sign, "Sign","Unsigned","Signed") END; //IF LEFT(STRING(in),1) ≠ "#" THEN in:=EXPR("#"+in+"d") END; //correct the format - no longer needed CASE IF bits=1 THEN bits:=GETBITS(#) END //use system bitw IF bits=2 THEN bits:=GETBITS(in) END //use input bitw DEFAULT bits:=2^(bits) END; IF sign=2 THEN bits:=1-bits END; SETBITS(SETBASE(in,base-1),bits);  //R→B(B→R(in),bits,base-1) //old command END;
 « Next Oldest | Next Newest »

 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: 1 Guest(s)