Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

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

 
 
0
Discomonkey
Asked:
Discomonkey
1 Solution
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now