?
Solved

Bit level Manipulation

Posted on 2003-02-19
7
Medium Priority
?
332 Views
Last Modified: 2010-04-15
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
Comment
Question by:Discomonkey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 6

Expert Comment

by:gj62
ID: 7984025
Sounds like homework - why the restrictions?  Have you any code you've started to work with?
0
 
LVL 1

Author Comment

by:Discomonkey
ID: 7984069
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
 
LVL 1

Author Comment

by:Discomonkey
ID: 7984084
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
Industry Leaders: 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!

 
LVL 1

Author Comment

by:Discomonkey
ID: 7984090
/*
 * 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
 
LVL 6

Expert Comment

by:gj62
ID: 7984213
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
 

Expert Comment

by:modulo
ID: 7984356
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
 
LVL 8

Accepted Solution

by:
akshayxx earned 400 total points
ID: 7984696
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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question