Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the value of the least significant bit in a number?

I'm working on a programming project and one of things I need to do is write a function that returns a mask that marks the value of the least significant 1 bit. Any ideas on how I can determine the value using bitwise operators?

ex:  0000 0000 0000 0000 0000 0000 0110 0000 = 96 What can I do with the # 96 to turn it into: 0000 0000 0000 0000 0000 0000 0010 0000 = 32 

I've been slamming my head against the wall for hours trying to figure this out any help would be greatly appreciated!

like image 395
Riptyde4 Avatar asked Sep 14 '13 21:09

Riptyde4


People also ask

What is the value of the least significant bit?

In computing, the least significant bit is the bit which is farthest to the right and holds the least value in a multi-bit binary number. As binary numbers are largely used in computing and other related areas, the least significant bit holds importance, especially when it comes to transmission of binary numbers.

What is least significant bit in decimal number?

When the MSB in a sequence is farthest to the left (or first), the least significant bit (LSB) is usually the one farthest to the right (or last). For example, the decimal number 157 is equal to the binary number 10011101 (or hexadecimal value 9D).

How do you find the least significant bit in C++?

int LSB = value & 1; for getting the least significant bit.

How do you find significant bits?

Given a number, find the greatest number less than the given a number which is the power of two or find the most significant bit number .


1 Answers

x &= -x; /* clears all but the lowest bit of x */ 
like image 98
R.. GitHub STOP HELPING ICE Avatar answered Oct 13 '22 04:10

R.. GitHub STOP HELPING ICE