Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
bitwise shift help
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Kvetch Kvetch, post: 4656325"] Hello, I am new to Ruby and was wondering if there is an easier/faster way to determine if a bit is set in a number. For example, If my number is 1011000010 and I want to check to see if 3rd bit is set so 1011000010 1000010000 ---------- 0000 - So 3rd bit is not set My code is y = 1 << 3 x = 0b1011000010 if ( x & y ) == 1 puts "The 3rd bit is set" else puts "The 3rd bit is not set" end Is there a better/faster method of achieving this bit check? Thank you [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
bitwise shift help
Top