-6

Possible Duplicate:
Bitwise Operation and Usage

x is the input. need to put either 0, 1, x, or x̅ :

    x & 0 = 0

    x & 1 = x

    x | 0 = x
    x | 1 = 0
    x ^ 0 = 1
    x ^ 1 = 
Community
  • 1
  • 1
  • 6
    1, x̅, x, x, 0, x in no particular order :-) See http://stackoverflow.com/questions/1746613/bitwise-operation-and-usage/1746642#1746642, then go do your own homework :-) – paxdiablo Feb 04 '13 at 04:56
  • 3
    My goodness. I'm embarrassed by the number of posts coming from classmates in CS61C. You go to UC Berkeley. Learn to read the manual. Bitwise operations are also VERY important to learn, so I'd recommend doing so before the first exam... – A fellow classmate Feb 04 '13 at 05:02

2 Answers2

1

If x is a boolean, then !x is the boolean negation of x. That's your 'flip'.

For turn on and turn off, just do x = 1 and x = 0

Patashu
  • 21,443
  • 3
  • 45
  • 53
1
x & 0 = 0

x & 1 = x

x | 0 = x
x | 1 = 1
x ^ 0 = x
x ^ 1 = 0 if x is 1, 1 if x is 0
James Anderson
  • 27,109
  • 7
  • 50
  • 78
  • 1
    Re that last one, did you not see x̅ as one of the possible answers? And, please, surely we have enough unthinking monkeys in the IT industry without releasing more :-) – paxdiablo Feb 04 '13 at 05:09
  • @paxdiablo -- "!" is not a bitwise operator -- the question seems to imply operations that effect a single bit. – James Anderson Feb 04 '13 at 05:58
  • Perhaps I was unclaer (wouldn't be the first time) - I meant that `x ^ 1 = 0 if x is 1, 1 if x is 0` could simply be written as `x ^ 1 = x̅`. And yes, I agree that these were single bit ops, otherwise that equality wouldn't make sense. – paxdiablo Feb 04 '13 at 06:06
  • The monkey comment wasn't disparaging you, BTW, just I'm not a big fan of helping people who don't even seem to make an effort. In the real world, they won't have their mothers there to wipe their bottoms for them :-) – paxdiablo Feb 04 '13 at 06:08