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
Printable View
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
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;
for setting the 6th bit:
x | (1<<5)
for unsetting the 6th bit:
x & (~(1<<5))
hope it helps.
:)
[QUOTE=dattu.kv;20998]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[/QUOTE]
You could also use the OR and AND operators to help you put.
#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
what the hell is the answr..