Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on Set sixth bit to 1 within the C and C++ forums, part of the Software Development category; Given a sixteen bit number. How can sixth bit can be set to 1 irrespective of its initial value and sixth bit reset to zero irrespective of its initial value...
|
|||||||
|
|||
|
Set sixth bit to 1
Given a sixteen bit number. How can sixth bit can be set to 1 irrespective of its initial value and sixth bit reset to zero irrespective of its initial value
|
| Sponsored Links |
|
|||
|
Re: Set sixth bit to 1
suppose 'a' contains 16 bit number. And initialize b with 32.
a=a|b; /*this will convert 6th bit to One irrespective of its original bit*/ now for making 6th bit 0, load b with 65503 and do the following. a=a&b; |
|
|||
|
Re: Set sixth bit to 1
Quote:
#define MASK1 0x0040 // Note that 6th bit is 1, counting from 0 #define MASK2 0xffbf // Note that the 6th bit is 0 // Set 6th bit of x to 1 x = x | MASK1 // Set 6th bit of x to 0 x = x & MASK2 |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|