Integer Confusion and :
01-25-2017, 03:54 PM
Post: #1
 KeithB Senior Member Posts: 347 Joined: Jan 2017
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?
01-25-2017, 04:18 PM
Post: #2
 Han Senior Member Posts: 1,882 Joined: Dec 2013
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
01-25-2017, 04:37 PM
Post: #3
 KeithB Senior Member Posts: 347 Joined: Jan 2017
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?
01-25-2017, 06:02 PM (This post was last modified: 01-25-2017 06:07 PM by Tim Wessman.)
Post: #4
 Tim Wessman Senior Member Posts: 2,283 Joined: Dec 2013
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.
01-25-2017, 06:28 PM
Post: #5
 KeithB Senior Member Posts: 347 Joined: Jan 2017
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.
01-25-2017, 07:01 PM (This post was last modified: 01-25-2017 07:25 PM by Han.)
Post: #6
 Han Senior Member Posts: 1,882 Joined: Dec 2013
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
01-26-2017, 01:30 AM
Post: #7
 mark4flies Member Posts: 115 Joined: Jan 2015
RE: Integer Confusion and :
1 +
For better RNG. Everybody benefits at low cost. Please consider it.
01-26-2017, 06:53 AM
Post: #8
 cyrille de brĂ©bisson Senior Member Posts: 1,047 Joined: Dec 2013
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.
01-26-2017, 05:03 PM
Post: #9
 KeithB Senior Member Posts: 347 Joined: Jan 2017
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.
 « Next Oldest | Next Newest »

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