×

# lowest set bit

 0 why does n&!(n-1) for n=6 gives 0 in C++ and 2 in python . it should give 2 though . asked 12 Sep '17, 22:42 3★junior_g 44●4 accept rate: 0%

 1 ! is an invalid operator in python but in c++ it coverts a true statement to false and vice versa . The real compliment operator is ~ . By convention in c++ every positive number is true in c++ and 0 is false . So ! operator converts the positive number which is true into false which translates to 0 . And the AND operation with 0 yields 0. answered 12 Sep '17, 23:07 986●1●9 accept rate: 12%
 0 Extract lowest set bit (BLSI) is -n & n. Wikipedia (Bit Manipulation) has a decent section on this and other bitwise operations. answered 16 Sep '17, 02:20 25●4 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,917
×280
×77

question asked: 12 Sep '17, 22:42

question was seen: 505 times

last updated: 16 Sep '17, 08:31