• C

Bit level Manipulation

Hey experts!  I hope you are prepared for an onslaught of questions I have for you.

I'm doing bit level manipulations in C.  I am trying to basic manipulations using a limited amount of operations.

bitXor - x^y using only ~ and & 
    Example: bitXor(4, 5) = 1
    Legal ops: ~ &
    Max ops: 14
 

How do I program the BitXor with just ~ and &?  I am restricted to those two operations and and being able to create local variables and const values.  anyone got ideas?

I'll be handing out more nad more points, I have a ton and not afraid to dump them :)

**Update new question below, I answered my own question, I double the points though

 
 
LVL 1
DiscomonkeyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gj62Commented:
Sounds like homework - why the restrictions?  Have you any code you've started to work with?
0
DiscomonkeyAuthor Commented:
You are correct, this is homework.  The restrictions are in place to help confuse me.(haha)  I would orginally have loved to sit down and figure these out, but time is thin and I need a little help.(spent last couple of days finishing a huge project, this one is due at midnight)  The system is real simple, I have skeleton code, I just have to fill in the blanks so to speak.  You can consider these are puzzlers, because that is generally what they are really.  

This is straight out of my code...
*
 * bitXor - x^y using only ~ and & 
 *   Example: bitXor(4, 5) = 1
 *   Legal ops: ~ &
 *   Max ops: 14
 *   Rating: 2
 */
int bitXor(int x, int y) {

  return 2;
}

in the comments you can see restrictions, overall goal, etc.

in place of return 2, of course something else is to be put there.

Rating is the difficulty of the problem from 1 to 4, 4 being hard.

So any help will be gladly appreciated... I have no partner for this project and my time is low, so I can only rely on the help of you guys.

0
DiscomonkeyAuthor Commented:
ok I figured out my own question:

int bitXor(int x, int y) {

     int z = ~x & y;
     int zz = x & ~y;
     int zzz = ~z & ~zz;
     zzz = ~zzz;

  return zzz;

but I have lots more
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

DiscomonkeyAuthor Commented:
/*
 * isNotEqual - return 0 if x == y, and 1 otherwise
 *   Examples: isNotEqual(5,5) = 0, isNotEqual(4,5) = 1
 *   Legal ops: ! ~ & ^ | + << >>
 *   Max ops: 6
 *   Rating: 2
 */
int isNotEqual(int x, int y) {
  return 2;
}
0
gj62Commented:
It is against the policies of this board for you to (a) ask homework questions and for (b) us to answer.  That said, generally if you have done a majority of the work and are stuck on a specific piece of code, some good soul will help you out.  However, nobody should post the answer to a question without seeing an attempt by you to answer.
0
moduloCommented:
Hi Discomonkey

gj62 is correct.
I'll monitor the Q to see no copy/paste answers are published.
Basically all info should come from your books !

modulo

Community Support Moderator
Experts Exchange
0
akshayxxCommented:
if you have done your basic Electronics course .. u can find how u can implements all the basic gates using .. NAND gates only ..
NAND = combination of NOT and AND gate.
and other basic gates are ..
AND , OR, NOT, XOR

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.