base conversion problems... - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: base conversion problems... (/thread-8953.html) base conversion problems... - webmasterpdx - 09-01-2017 10:24 AM Converting between bases is something I need to do a lot of in embedded software. However, the HP prime makes it difficult. I don't have a problem with converting from other bases to decimal, but converting from decimal to other bases is the problem. Sure I can use convert, but thats way way too much work. I tried highlighting a result and using shift-base (integer editor), but I can't seem to edit in any format other than the default base (which is set to hex).....as this is the most common base I use apart from decimal. Also, I read somewhere that the highlighted value should appear in the integer editor, but it doesn't. Is there a fast way to convert from decimal to hex....it's such a fundamental operation that if it isn't there, it needs to be??????????? On just about every other calculator in the world, there are hex,oct,bin,dec buttons or menu options, and you type your number and hit the button and the number is converted....try it on the TI calculators.....you'll see what I mean.... It should be possible to convert from any base to any other base in 2 key presses. I don't mind typing #23h, but I need a way to convert that to any other base quickly. I don't even mind using an integer editor, if I can edit in any base...however, I think you'd be better off dumping the integer editor and putting in a menu with hex,oct,bin,dec functionality. Thx -frustrated RE: base conversion problems... - webmasterpdx - 09-01-2017 11:47 AM I did discover R->B, which is too much to type for the frequency with which I do these conversions. Currently I'm using my old TI86 or an app on my phone to do conversions as the prime is too cumbersome. I also discovered how to get a decimal number into the integer editor. You have to enter it in the format #43d hit enter, and enter the integer editor. If I'd just had 43 on the stack, the editor doesn't open and the # character appears on the input line. Unfortunately, edit inside the editor only allows the current base (hex for me)....when it really should do it in whatever you change the base to be. I'm really surprised the prime has made base conversion so cumbersome. Maybe I'll write a program to produce the menu method and change the definition of the base key... I'd highly recommend changes in this area for a future release of the firmware. Thx -D RE: base conversion problems... - Helge Gabert - 09-01-2017 05:24 PM Base conversion works just fine for me. Insider the editor, +- cycles through the bases, regardless of what your default base is. I don't understand why you would be stuck in hex. Also, what could be easier than R->B()? What is too much typing? Or create a user function called RB (either as a program, or via the Define setup). RE: base conversion problems... - webmasterpdx - 09-02-2017 03:23 AM R->B() is too much typing. I do conversions like you use the x sign. It'd be like you having to look up multiply in the catalog....you'd find that annoying right? People doing embedded development often end up having to do loads of base conversions while debugging their assembly language code. Most advanced calculators have menus like I suggested. I really don't care about the mechanism, but I need to be able to convert quickly. The editor....here is my problem. I enter the editor....now lets say I want to convert 43d to hex.....If I rotate the base to decimal inside the editor....any number I type only shows up in the hex field....not the decimal field. Thx -D RE: base conversion problems... - Helge Gabert - 09-02-2017 05:34 AM Call the editor after putting #43d into the history of the home screen -- then rotate +. Ok. #2Bh. Or define user function RB as R->B(X). RB(43) returns #2Bh. Super easy. RE: base conversion problems... - Joe Horn - 09-02-2017 05:58 AM The HP Prime has a USER MODE which allows the user to assign functions and programs to keys, thus making it possible to do anything you want in the fewest possible keystrokes. If your favorite function takes more keystrokes than you'd like, just assign it to a key, and from now on it's available in ONE keystroke. Don't like the interface? Prime is programmable. Write your own. Then assign it to a key. In other words, we all have three options available to us. (1) Bemoan the fact that the gravel hurts our bare feet. (2) Demand that the world pave itself. (3) Put on shoes. RE: base conversion problems... - Stevetuc - 09-02-2017 08:27 AM Take a look at baseconv in the program section (scroll to end of post for latest code) - it uses a simple menu system. If you are in rpn mode you can place the input on stack and then run baseconv(). You could assign baseconv() to a userkey or access from user menu. Input without a "#" is accepted as decimal whatever integer mode you are in. Example: Enter 255 onto stack (I'm assuming Rpn mode) baseconv() Press enter again to accept System base and again for System size And you get result #FFh RE: base conversion problems... - webmasterpdx - 09-02-2017 10:15 AM User mode and baseconv sound like they'll do the job. Let me give those a shot! Thx -D RE: base conversion problems... - Stevetuc - 09-02-2017 08:35 PM The prog given here might work even better- 1 tap conversion when in locked user and Rpn mode http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv021.cgi?read=252437 Code: ``` KEY K_Minus() BEGIN LOCAL nb; CHOOSE(nb, "Base", "Bin", "Oct", "Dec", "Hex"); Base:=nb-1; STARTVIEW(6, 1); STARTVIEW(-1, 1); END;``` This code is what I ended up using. With user mode locked on and #num in stack press Base (-) key then tap the menu for desired conversion - simples! RE: base conversion problems... - webmasterpdx - 09-03-2017 02:07 AM Yeah, I realize I'm going to need to create my own conversion program. I notice that the # char is also available as the key Alpha-3, so the integer editor can be overwritten in User mode. I'm mulling over a few different ways to do it. I'm thinking that maybe the best way would be to type Shift-Base and have that run a program that takes the input line and convert it into hex, decimal, octal and binary and store the results in the global variables H, D, O and B respectively. This is probably the most convenient way to do manual conversions. RE: base conversion problems... - Eddie W. Shore - 09-04-2017 07:41 PM (09-02-2017 05:58 AM)Joe Horn Wrote:  The HP Prime has a USER MODE which allows the user to assign functions and programs to keys, thus making it possible to do anything you want in the fewest possible keystrokes. If your favorite function takes more keystrokes than you'd like, just assign it to a key, and from now on it's available in ONE keystroke. Don't like the interface? Prime is programmable. Write your own. Then assign it to a key. In other words, we all have three options available to us. (1) Bemoan the fact that the gravel hurts our bare feet. (2) Demand that the world pave itself. (3) Put on shoes. I have yet to see the world pave itself. RE: base conversion problems... - leprechaun - 09-05-2017 07:05 AM The programming has its restrictions. Especially when it comes to the topics webmasterpdx is talking about in his posts. And there are issues with convenience, productivity and keystrokes from time to time. Although I am surely not fully qualified to talk about the programming and customization of the prime, I notice that there are still flaws and drawbacks. Quote:The HP Prime has a USER MODE which allows the user to assign functions and programs to keys, thus making it possible to do anything you want in the fewest possible keystrokes. If your favorite function takes more keystrokes than you'd like, just assign it to a key, and from now on it's available in ONE keystroke. Don't like the interface? Prime is programmable. Write your own. Then assign it to a key. In other words, we all have three options available to us. (1) Bemoan the fact that the gravel hurts our bare feet. (2) Demand that the world pave itself. (3) Put on shoes. (4) get leather and tools and learn how to craft shoes....... ;-) (5) shoot cows, learn skinning goto (4) Don't make things too easy for HP. A company should try to offer the best possible sollutions and not hide behind such things. That leads to reputation in a competing market. RE: base conversion problems... - webmasterpdx - 09-05-2017 08:26 AM I have a decent program for converting bases. I overloaded the # key (shift-3) in user mode. Note that there are problems with overloading the shift-minus (base function) which is unreliable, but shift-3 is reliable. This must be run in Home mode as you can't push numbers of the form #nnb on the CAS stack. So to use, you'd put it in Home mode, Enter your number and hit enter to push it onto the stack. Then shift-user, alpha-3 will run the program. Select the base you want to convert to via the menu. The program will exit itself. It's pretty quick and easy to use. First, here are some utility functions I use, including the key definition. Code: ``` // BASE CONVERSION KEY KA_3() BEGIN RETURN STRING(EVAL(MBase())); END; // DEFINE MENU EXPORT PUTMENU(mTXT) BEGIN DRAWMENU(mTXT(1),mTXT(2),mTXT(3),mTXT(4),mTXT(5),mTXT(6)); END; // SETS mSEL GLOBAL VIA MENU SELECT EXPORT GETMENU(mx,my,mTXT) BEGIN LOCAL mSEL; mSEL:=0; IF my≥220 AND my≤239 THEN CASE  IF mx≥0 AND mx≤51 AND mTXT(1)>"" THEN   mSEL:=1;  END;  IF mx≥53 AND mx≤104 AND mTXT(2)>"" THEN   mSEL:=2;  END;  IF mx≥106 AND mx≤157 AND mTXT(3)>"" THEN   mSEL:=3;  END;  IF mx≥159 AND mx≤210 AND mTXT(4)>"" THEN   mSEL:=4;  END;  IF mx≥212 AND mx≤263 AND mTXT(5)>"" THEN   mSEL:=5;  END;  IF mx≥265 AND mx≤319 AND mTXT(6)>"" THEN   mSEL:=6;  END; END; // CASE END; // IF MENU RETURN mSEL; END; // BEGIN``` And here is the base conversion program itself. Code: ``` EXPORT MBase() BEGIN LOCAL men,m,m1,mx,my,s; // initialize men:={"","BIN","OCT","DEC","HEX","EXIT"}; PUTMENU(men); REPEAT // WAIT FOR A MOUSE CLICK  m:=WAIT(−1); UNTIL (m(1)==3 OR m(1)==7); mx:=m(2); my:=m(3); s:=GETMENU(mx,my,men); IF (s==1  OR s==6) THEN RETURN END; RETURN s:=SETBASE(Ans(1),s-1); END; // BEGIN``` Enjoy... RE: base conversion problems... - webmasterpdx - 09-05-2017 08:52 AM With respect to the comment above my last one, the prime is a very powerful calculator, but it needs nicer wrappers to get at the great features. e.g. The menu stuff should have the functions I use in the program above...that's a perfect example. There is a terminal output....they should provide a terminal window with scrollbar and the ability to both do input and output via the terminal....kind of like stdout in an xview window. There are a lot of applications where all you want is text, and the terminal provides the perfect conduit to produce these utilities. There are a bunch of stuff like this I'd love to see and wouldn't add much to the firmware. Also better coexistance between the CAS and HOME views. In fact, because the CAS stuff is transferred from XCas, perhaps the best way to do this is to make the entire home system work with the CAS i/o. I'm fairly new to the prime....just got it a month or two ago, and it definitely requires getting used to. Calculators are kind of a ripoff, as you can get an app for a tablet for much less money. However, I love the feel of a calculator and when you are intimate with it, they can be very productive tools. So, it's important that HP keeps this product alive. It's also important that they realize that students are not the only customers. I'm really tired of hearing "we won't add that feature as it could allow students to get around exam mode".....maybe the solution is to have 2 calculators...one for students and a "pro" version for professionals. Finally, I gotta mention this. I find it very annoying that I have to use a flashlight to see the keys because of the poor choice of colors. I sure hope the person who came up with those is no longer employed at HP. Also, they need to assign a different hardware number to the version with the darker keys. I was unable to purchase one (even though it was on the market) as the sales people at HP dont' know their own products so when I tried to order it that way, they said what you buy is what you get, and they had no way to distinguish between the dark keys and light ones....I was unable to find a local store at the time with the dark keys.....so I run my calculator with a book light to see the keys. :-) RE: base conversion problems... - Stevetuc - 09-05-2017 11:29 AM (09-05-2017 08:26 AM)webmasterpdx Wrote:  I have a decent program for converting bases... First, here are some utility functions I use, including the key definition. Code: ``` // BASE CONVERSION KEY KA_3() BEGIN RETURN STRING(EVAL(MBase())); END; // DEFINE MENU EXPORT PUTMENU(mTXT) BEGIN DRAWMENU(mTXT(1),mTXT(2),mTXT(3),mTXT(4),mTXT(5),mTXT(6)); END; // SETS mSEL GLOBAL VIA MENU SELECT EXPORT GETMENU(mx,my,mTXT) BEGIN LOCAL mSEL; mSEL:=0; IF my≥220 AND my≤239 THEN CASE  IF mx≥0 AND mx≤51 AND mTXT(1)>"" THEN   mSEL:=1;  END;  IF mx≥53 AND mx≤104 AND mTXT(2)>"" THEN   mSEL:=2;  END;  IF mx≥106 AND mx≤157 AND mTXT(3)>"" THEN   mSEL:=3;  END;  IF mx≥159 AND mx≤210 AND mTXT(4)>"" THEN   mSEL:=4;  END;  IF mx≥212 AND mx≤263 AND mTXT(5)>"" THEN   mSEL:=5;  END;  IF mx≥265 AND mx≤319 AND mTXT(6)>"" THEN   mSEL:=6;  END; END; // CASE END; // IF MENU RETURN mSEL; END; // BEGIN``` And here is the base conversion program itself. Code: ``` EXPORT MBase() BEGIN LOCAL men,m,m1,mx,my,s; // initialize men:={"","BIN","OCT","DEC","HEX","EXIT"}; PUTMENU(men); REPEAT // WAIT FOR A MOUSE CLICK  m:=WAIT(−1); UNTIL (m(1)==3 OR m(1)==7); mx:=m(2); my:=m(3); s:=GETMENU(mx,my,men); IF (s==1  OR s==6) THEN RETURN END; RETURN s:=SETBASE(Ans(1),s-1); END; // BEGIN``` Enjoy... A couple of changes I made to my version allow the function MBase() to be also usable from the command line using passed parameter in both rpn and algebraic/textbook In the base conversion program: EXPORT MBase(in) ... RETURN s:=SETBASE(in,s-1); In the key definitions: ... RETURN STRING(EVAL(MBase(Ans(1)))); It may be useful to some.. RE: base conversion problems... - webmasterpdx - 09-05-2017 11:09 PM I'll have to play around with that...good idea Steve... Thx -Donald