Base Conversions (to any base 2-36) - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: HP Prime Software Library (/forum-15.html) +--- Thread: Base Conversions (to any base 2-36) (/thread-14252.html) |
Base Conversions (to any base 2-36) - Eddie W. Shore - 12-28-2019 06:27 PM Blog Link: http://edspi31415.blogspot.com/2019/12/hp-prime-base-conversions.html Introduction The program BASEDEC converts a number in a base representation to decimal (base 10). BASEDEC accepts any positive number, including non-integers up to base 36. Each of the letters of alphabet represents a value: A = 10 B = 11 C = 12 D = 13 E = 14 F = 15 ... Z = 35 BASEDEC takes two arguments: number to be converted, entered as a string; and the base representation of the number. Examples: BASEDEC("531",8) converts 531_8 to decimal. Result: 345 BASEDEC("63.95A", 11) converts 63.95A_11 to decimal. Result: 69.86701728 BASEDEC("4H", 18) converts 4H_18 to decimal. Result: 89 (H = 17) HP Prime Program BASEDEC Code:
Introduction Part II The program DECBASE converts a number in decimal form to any base you want. DECBASE works will all positive real numbers. There are three arguments to DECBASE: * The number in decimal form * The desired base * Accuracy: how many decimal points do you want. Conversions from decimal to other bases are approximations. If the number is a integer (frac(number) = 0), then this argument is ignored (put 0). The result is returned as a string. Examples: DECBASE(69, 6, 0) converts 69 to base 6. Result: "153" DECBASE(5.875, 8, 4) converts 5.875 to base 8 to four decimals. Result: "5.7000" (exact: 5.7_8) DECBASE(635.05, 12, 12) converts 635.05 to base 12 to twelve decimals. Result: "44B.072497249724" (exact: 44B.07249..._12 (7249 repeats)) HP Prime Program DECBASE Code:
RE: Base Conversions (to any base 2-36) - Stevetuc - 12-29-2019 04:48 PM Nice programs! if I run the program using Shift Program and use the fill form all is well, but if I run from home screen as BASEDEC("531",8) I get Code: 0+when(al>64,al-55,EXPR(sd))*324+when(al>64,al-55,EXPR(sd))*18+when(al>64,al-55,EXPR(sd))*1 This is on android 2.1.14346 (2019 11 21) Wonder why the when() statements not being evaluated? RE: Base Conversions (to any base 2-36) - Eddie W. Shore - 12-30-2019 04:26 PM That's a strange result. Possibly a bug? Thank you for the compliment! RE: Base Conversions (to any base 2-36) - Joe Horn - 01-01-2020 05:42 AM Happy 2PI! (in base 26) |