Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in C only
Search
Advanced Search
Forums
Product Launch
Updates
Today's Posts
Member List
Calendar
Home
Forum
Topic
C
bitwise operation....help
Collapse
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
jerico
New Member
Join Date:
Sep 2006
Posts:
39
#1
bitwise operation....help
Oct 7 '06, 07:23 PM
Hi.Given a number ,say 15, whose binary equivalent is 1111, how can the bit value of any position can be obtained using bitwise operators?Thank s for any help.
Jerico
Banfa
Recognized Expert
Expert
Join Date:
Feb 2006
Posts:
9067
#2
Oct 7 '06, 08:19 PM
select the bit you want, say 3 bit (0100 = 0x04) AND the value with that bit and shift right by the number of 0 (2 in this case)
bit = (number & 0x04) >> 2;
bit will have either the value 0 or the value 1 depending on the value of the third bit in number.
Preferably bitwise operations should always be carried out on unsigned integers.
Comment
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment