You are not logged in. Please login at www.codechef.com 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

1★pandey_96
667
accept rate: 0%

edited 20 Jan '18, 09:07


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

link

answered 20 Jan '18, 11:43

namitp's gravatar image

3★namitp
952
accept rate: 0%

edited 20 Jan '18, 11:43

toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×77

question asked: 20 Jan '18, 09:07

question was seen: 309 times

last updated: 20 Jan '18, 11:43