You are not logged in. Please login at to post your questions!


lowest set bit

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

junior_g's gravatar image

accept rate: 0%

! 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

trashmaster's gravatar image

accept rate: 12%

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

kungfuboner's gravatar image

accept rate: 0%

Answer is hidden as author is suspended. Click here to view.

answered 16 Sep '17, 08:31

ashikajain's gravatar image

accept rate: 0%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • 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:


question asked: 12 Sep '17, 22:42

question was seen: 505 times

last updated: 16 Sep '17, 08:31