HP Forums

Full Version: Integer Confusion and :
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
All this talking about random numbers has made me want to port the Marsenne twister to HP-PPL. Most algorithms use bit twiddling and 32 bit integers.

Given the "binary explorer" I assume that most numbers are 64 bit. Is there a way to declare a 32 bit variable/number? I see the intriguing ':' operator, but as far as I could tell, it is undocumented. (It was a bit tedious searching the manual for ':' - whoever wrote the manual sure likes his colons!)

I also see the SETBITS() command. Can I use that on a variable to make it 32 bits?
You can change the integer bits in the settings page. They can be set to signed or unsigned, and the word size can be up to 64 bits.
Ah, yes, and I see that the default is unsigned, 32 bit which is what I want. Is there anyway to specify that a variable is an integer?
You cannot force a type on variable (that will restrict anything but that type from being stored in it).


#123:32o would be an unsigned, 32 bit integer in octal.
#123:-42h would be a signed, 42 bit integer in hex.
and so on...
Ah, that is why you can have a -32 bit integer! I was wondering why the size of the integer was allowed to be negative.
(01-25-2017 04:37 PM)KeithB Wrote: [ -> ]Ah, yes, and I see that the default is unsigned, 32 bit which is what I want. Is there anyway to specify that a variable is an integer?

Not really, but there are R->B and B->R commands to switch between real numbers and "integer" types.
1 +
For better RNG. Everybody benefits at low cost. Please consider it.
Hello,

If you are planning to work with integers in a program, remember that you can access integers bits using the () syntax as in:
LOCAL a:= #12345h;
a(x) to get/set the xth bit in the integer and that
a(x,y) will allow you to set/get the y bits at pos x in the integer.

Cyrille
Thanks. Hard to remember when it is not documented! 8^)

Also, I found that it is much better to work with Lists than Matrices. Lists will store integers, Matrices don't.
Reference URL's