how to use inverse in C

Viewed 101712

[how to use ~ operator ]

I have a structure say Alpha. I know the value of element inside Alpha (say a) which can be 0 or 1 - I want the other element of same structure to take inverse value of Alpha.a. For example:

if Alpha.a = 1
then Alpha.b = 0

and vice versa

I have tried:

Alpha.b = ~ (Alpha.a)

But unfortunately it doesnt work - when Alpha.a is 1, Alpha.b gets set to 254

Any ideas?

Thanks and regards,

SamPrat

7 Answers
Related