hey guys!!!

iam just working on speed of the codes..
and i just want to extract the last bit of the given variable.could u help me???
note:dont extract the bits by dividing it by 2:):)

6 Years
Discussion Span
Last Post by vishwanath.m

i just want to extract the last bit of the given variable.

Which bit do you think is the "last bit"? The term is ambiguous as it could be interpreted as either the most significant bit or the least significant bit.

note:dont extract the bits by dividing it by 2

Let me guess: this is a restriction on the homework you so carefully didn't say this question is based upon? :icon_rolleyes:

Edited by Narue: n/a


you check the least significant bit to determine if it's even or odd, because it's 2^0 = 1.

thus you can shift the bits the proper direction and determine if the bit is set or not.

in case bits were never described this way to you:
[ ] [ ] [ ] [ ]
we have four bits here, each with a value of:
[2^3] [2^2] [2^1] [2^0]

least sig. bit is set? value = 1.
lest sig. and 2^1 = 3.

for a byte this continues to 2^7.

Edited by pseudorandom21: n/a


lets say its the most significant bit

k i just want to check whether the no s even or odd using msb

Apparently you don't understand the difference between most significant and least significant. :icon_rolleyes: If you're checking for even/odd, you test the least significant bit:

if ((value & 1) == 0) {
    // Even
else {
    // Odd

Edited by Narue: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.