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:):)

vishwanath.m
0
Newbie Poster

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:):)

Jump to Posti 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

Jump to Postyou 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:

[ ] …

Narue
5,707
Bad Cop
Team Colleague

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 because:
*
n/a *

vishwanath.m
0
Newbie Poster

lets say its the most significant bit:D

vishwanath.m
0
Newbie Poster

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

pseudorandom21
166
Practically a Posting Shark

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 because:
*
n/a *

vishwanath.m
0
Newbie Poster

is this shifting faster than dividing it by 2 and checking

Narue
5,707
Bad Cop
Team Colleague

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 because:
*
n/a *

vishwanath.m
0
Newbie Poster

sorry that was lsb...k thanks:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.

Broken Link

**You're trying to visit a URL that doesn't currently exist on the web.**
Most likely, a member posted a link a long time ago to a web page that has since been removed.
It's also possible that there was a typo when posting the URL.
We redirect you to this notice instead of stripping out the link to preserve the integrity of the post.