|
-
Jan 4th, 2003, 12:25 AM
#1
Thread Starter
Hyperactive Member
bit comparing in c++
ok
i need to check if bit 5 is set (left to right), all the other bits can be set or not but as long as bit 5 is, how would i go about doing this.
00000000 00000000 00000000 00010000
I know a lot oF Vb, expert in C++, and i think in assembly.
MSVC++6.NET
vb6
masm
Windowz Xp
I find my self using this a lot in C++
__asm {
}
-
Jan 4th, 2003, 01:55 AM
#2
Hyperactive Member
Code:
//0x01==0001b,0x02==0010b,0x04==0100b,0x08==1000b,0x10==10000
if(0x10 & my32bitvariable)
{
//it is set, so do what you want here
}
-
Jan 4th, 2003, 05:37 AM
#3
Guru
More readably,
Code:
if(my32bitvariable & (1 << 4))
(It's really the 4th bit, since the counting is zero-based.)
-
Jan 4th, 2003, 10:12 AM
#4
There is no such thing as the 0th something.
It's the 5th bit, the one with index 4.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 4th, 2003, 05:33 PM
#5
Guru
I call the rightmost bit the 0th bit. *shrug*
-
Jan 5th, 2003, 07:26 AM
#6
Sure, and there are 1024 metres in a kilometre
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 5th, 2003, 08:21 AM
#7
-
Jan 5th, 2003, 07:37 PM
#8
Fanatic Member
CB - Take a look in my sig!
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Jan 5th, 2003, 08:19 PM
#9
Where do you think I have it from McCain?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 5th, 2003, 08:28 PM
#10
Fanatic Member
I just read it and thought "cool, that's in my sig!" I never thought that someone as good as you are would "learn" anything from someone like me, I feel honored
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Jan 5th, 2003, 08:35 PM
#11

I think it's cool.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|