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


How to Find first set bit

Find first set bit Given an integer an N, write a program to print the position of first set bit found from right side in the binary representation of the number.

I/P 18, Binary Representation 010010

O/P 2

I/P 19, Binary Representation 010011

O/P 1

Can anyone explain with the help of an example

asked 20 Jan '18, 09:07

pandey_96's gravatar image

accept rate: 0%

edited 20 Jan '18, 09:07

log2(number&(-number))+1 will give you the desired result. Hope this help.


answered 20 Jan '18, 11:43

namitp's gravatar image

accept rate: 0%

edited 20 Jan '18, 11:43

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: 20 Jan '18, 09:07

question was seen: 309 times

last updated: 20 Jan '18, 11:43