Computer Science Canada

Last 32 bits of an integer

Author:  cavetroll [ Mon Oct 13, 2008 12:48 am ]
Post subject:  Last 32 bits of an integer

I am trying to create a pseudo-random number generator and the algorithm I am looking into calls for me to find the last 32 bits of a number. Is there any bitwise operation that can do this for me? I would check the Turing F10 help but for some reason it doesn't work.


P.S. I have checked this out [Tutorial] Bitwise Operators, but it only lists a way to find a specific bit, I suppose I could write a function to find the last 32 for me but I am hoping there is an easier way.

Author:  OneOffDriveByPoster [ Mon Oct 13, 2008 8:05 am ]
Post subject:  Re: Last 32 bits of an integer

cavetroll @ Mon Oct 13, 2008 12:48 am wrote:
I am trying to create a pseudo-random number generator and the algorithm I am looking into calls for me to find the last 32 bits of a number. Is there any bitwise operation that can do this for me? I would check the Turing F10 help but for some reason it doesn't work.


P.S. I have checked this out [Tutorial] Bitwise Operators, but it only lists a way to find a specific bit, I suppose I could write a function to find the last 32 for me but I am hoping there is an easier way.
A bitmask is what you want. The funny thing is the most "int"s nowadays are only 32 bits. To get the last (or lowest) 32 bits, use 0xffffffff as your bitmask. You will want to AND with this mask. Note that the mask has only the last 32-bits set.

Author:  cavetroll [ Mon Oct 13, 2008 10:58 am ]
Post subject:  Re: Last 32 bits of an integer

Thank You

I guess I didn't quite understand the section on bit masking. I'll try re-reading it.

Author:  Insectoid [ Mon Oct 13, 2008 10:59 am ]
Post subject:  RE:Last 32 bits of an integer

a pseudo-random code eh? Sounds like fun!


: