Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Last 32 bits of an integer
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cavetroll




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
OneOffDriveByPoster




PostPosted: 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.
cavetroll




PostPosted: 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.
Insectoid




PostPosted: Mon Oct 13, 2008 10:59 am   Post subject: RE:Last 32 bits of an integer

a pseudo-random code eh? Sounds like fun!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: