Post Reply 
Integer Confusion and :
01-25-2017, 03:54 PM
Post: #1
Integer Confusion and :
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?
Find all posts by this user
Quote this message in a reply
01-25-2017, 04:18 PM
Post: #2
RE: Integer Confusion and :
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.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
01-25-2017, 04:37 PM
Post: #3
RE: Integer Confusion and :
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?
Find all posts by this user
Quote this message in a reply
01-25-2017, 06:02 PM (This post was last modified: 01-25-2017 06:07 PM by Tim Wessman.)
Post: #4
RE: Integer Confusion and :
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...

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
01-25-2017, 06:28 PM
Post: #5
RE: Integer Confusion and :
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.
Find all posts by this user
Quote this message in a reply
01-25-2017, 07:01 PM (This post was last modified: 01-25-2017 07:25 PM by Han.)
Post: #6
RE: Integer Confusion and :
(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.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
01-26-2017, 01:30 AM
Post: #7
RE: Integer Confusion and :
1 +
For better RNG. Everybody benefits at low cost. Please consider it.
Find all posts by this user
Quote this message in a reply
01-26-2017, 06:53 AM
Post: #8
RE: Integer Confusion and :
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

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
01-26-2017, 05:03 PM
Post: #9
RE: Integer Confusion and :
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.
Find all posts by this user
Quote this message in a reply
Post Reply 




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