Problem in counting program

06302020, 10:12 PM
(This post was last modified: 06302020 10:13 PM by cahlucas.)
Post: #1




Problem in counting program
Hi all,
At the moment I am making some programs for digital technology. Now I'm working on a program to count the ones in a binary integer. So, if you have the number #264h (#1001100100b) as input, the number 4 appears as the result. It works the same as the #B function on the HP16C or the nBITS function on the WP34s. Now an error has crept into this program that I don't understand. If I input the number # 192837645h (# 110010010100000110111011001000101b) as input, I get the number 14 as a result, which should have been 15. The strange thing is that the outcome is correct for other inputs. The error occurs during debugging, at the BITAND function with mask # 0F0F0F0F0F0F0F0Fh, see the code below (I use double lowercase letters for my variable names to distinguish them from builtin variables). Attached is the HP50g program from which I derived it, which works correctly. Can anyone help me with this problem? Sincerely, Karel. Code:
I use HP16C, WP34S emulator, HP35s, HP48GX, HP50g, and HP Prime G2. 

07012020, 04:52 AM
(This post was last modified: 07012020 04:56 AM by Joe Horn.)
Post: #2




RE: Problem in counting program
Try that input again after setting the wordsize to 64 bits (in Home Settings). Prime's default of 32 bits will cause the problem you're seeing. The 50g's default wordsize is 64 bits.
<0ɸ0> Joe 

07012020, 05:07 AM
Post: #3




RE: Problem in counting program
The following are general concepts that I am not sure if this is your case, nor with debugging.
 To send a 64bit integer you must have the variable "Bits" in 64, also from configuration in order to define the default input length, or also send an integer with the suffix #FF:64h.  Pragma must also obey this → pragma( integer(h64) ), you currently have h32, which is truncating your masks. If pragma is not defined, the Home setting will be used for the length of the integer. #192837645h may be converted to #92837645h (result 14) due to the mask altered by the h32 pragma and otherwise by the Home setting. Viga C  TD  FB 

07012020, 06:55 AM
Post: #4




RE: Problem in counting program
(07012020 04:52 AM)Joe Horn Wrote: Try that input again after setting the wordsize to 64 bits (in Home Settings). Prime's default of 32 bits will cause the problem you're seeing. The 50g's default wordsize is 64 bits. Dear Mr. Horn, The default wordsize was allready altered to 64 by me when initialling the calculator, so this is not causing the error. Thanks anyway. Sincerely, Karel. I use HP16C, WP34S emulator, HP35s, HP48GX, HP50g, and HP Prime G2. 

07012020, 07:01 AM
Post: #5




RE: Problem in counting program
(07012020 05:07 AM)Carlos295pz Wrote: The following are general concepts that I am not sure if this is your case, nor with debugging. Dear Mr. Carlos, The pragma setting of h32 was indeed the cause of the error. After setting this to h64, the answer (15) turned out to be good. Thank you very much! Sincerely, Karel. I use HP16C, WP34S emulator, HP35s, HP48GX, HP50g, and HP Prime G2. 

« Next Oldest  Next Newest »

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