Post Reply 
do not show number of bits
10-02-2024, 09:45 PM
Post: #1
do not show number of bits
Greetings,
I am writing a user-key program that returns/inserts a "color code".
The program ends with RETURN STRING(color);
There are several ways to enter the color.
>>One method uses a CHOOSE list where a color is selected from the list and sets (for example) color:=#FF00FFh; The returned string is #FF00FFh. Which is what I want.
>>Another method uses INPUT where a color is inserted in hex format. Such as #00FAD3h.
The returned string is #00FAD3h. Which is what I want.
>>A third method uses INPUT where a color is inserted with three RGB values.
For example R=128, G=255 and B=45 and color:=RGB(R,G,B);
The returned string is #80FF2D:32h. I know the number is the same with or without the number of digits displayed but this user key will be used to insert the color into the editor while I am writing a program and I would rather not have the ":32" in the program file.
Is there a way to hide the number of bits or do I have to strip the :32 from the string before returning?
Find all posts by this user
Quote this message in a reply
10-03-2024, 04:47 AM
Post: #2
RE: do not show number of bits
Your issue is caused by changing the default value of 'Bits' on the first page of the Home Settings (the edit field next to the 'Integers' drop-down). By default, this value is set to 32, and since RGB also returns a 32-bit value, there's no need to specify that the given value has a different bit-width. However, if you changed the value to something other than 32, the system will indicate that the resulting value has a different bit-width by appending information about the number of bits used. When you change this setting back to 32, the RGB result will no longer have the ":32h" at the end.

In a program, you can control this setting using the Bits variable. For example, at the beginning of your program, you can set Bits := 32 so that regardless of what is set in Home Settings, running this program will always set 32. This is a global variable that causes a permanent change to the system settings, so it might be worth temporarily saving its value and restoring it to its previous state before returning the string after the conversion.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
10-03-2024, 07:13 PM (This post was last modified: 10-03-2024 10:41 PM by glfiedler.)
Post: #3
RE: do not show number of bits
Piotr,
Thank you very much for taking the time to respond to me. I always find your answers thoughtful and helpful.
My home settings are always at 32-bit integers. HOWEVER, I also always check the "signed integers by default" checkbox.
When I look at the Bits system variable it is equal to -32 obviously indicating negative values are allowed. As you would expect if I uncheck the box Bits becomes 32.
Since colors codes CANNOT be negative it makes sense that RGB() would use unsigned values and Bits would be 32.
Solved! When using RGB() use unsigned 32-bit integers. As you suggested it is very simple to temporarily save the current Bits value, change Bits to 32 and reset at the end of the program.
Regards,
Jerry
Update: Tried temp saving Bits but I could not reset the Bits to -32 at end. Routine failed. I am assuming since the first line of the routine set Bits to 32 it did not like the -32. I just don't understand the use of that settings checkbox. My program works great with the box unchecked which of course is the same as setting Bits to 32.
What is the purpose of the check box?
Find all posts by this user
Quote this message in a reply
10-04-2024, 07:54 PM
Post: #4
RE: do not show number of bits
(10-03-2024 07:13 PM)glfiedler Wrote:  Tried temp saving Bits but I could not reset the Bits to -32 at end. Routine failed. I am assuming since the first line of the routine set Bits to 32 it did not like the -32. I just don't understand the use of that settings checkbox. My program works great with the box unchecked which of course is the same as setting Bits to 32.
What is the purpose of the check box?

Well... this seems to be one of the shortcomings of the HP Prime. If this checkbox doesn’t have a dedicated variable to control it, it should enable when a negative value is entered in Bits (since Bits has a negative value when the checkbox is manually enabled). Unfortunately, I’m not able to help with this. The best option would be to add it to the bug tracker and ask Jeff to look into it.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
10-05-2024, 09:01 AM
Post: #5
RE: do not show number of bits
There is a variable “Signed” that reflects/controls the “+/-“ checkbox.

Nigel (UK)
Find all posts by this user
Quote this message in a reply
10-05-2024, 09:39 AM
Post: #6
RE: do not show number of bits
(10-05-2024 09:01 AM)Nigel (UK) Wrote:  There is a variable “Signed” that reflects/controls the “+/-“ checkbox.

Thanks, Nigel. I don't know how I could have missed that Smile

@glfiedler
So we have a working solution; you just need to temporarily store the current values of two variables. Nevertheless, I see a small issue with the Bits value turning negative when Signed is set to 1. I believe this is incorrect behavior, as Signed should not affect the Bits value. In this case, when restoring the previous Bits value, it needs to be set as an absolute value for it to work correctly.

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




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