Binary Operation help.

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 2
Reputation: Sauron911 is an unknown quantity at this point 
Solved Threads: 0
Sauron911 Sauron911 is offline Offline
Newbie Poster

Binary Operation help.

 
0
  #1
Nov 7th, 2008
Basically what my program does.
It has one main.
It has one function.

The function is:
  1. int humhum (unsigned long x, unsigned long y)
  2. {
  3. unsigned long res;
  4. printf("Enter an integer for x:");
  5. scanf( "%ul", &x);
  6. printf("\nEnter an integer for y:");
  7. scanf("%ul", &y);
  8. res = x ^ y;
  9.  
  10. }

Now res will use exclusive ^OR to compare two numbers in binary mode. But what do i do here to use res and and count how many 0s does res have?

I also need to call this function in the main, and then state that this many zeroes are in res.

Thank you for your help.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,021
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 299
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: Binary Operation help.

 
0
  #2
Nov 7th, 2008
This site might help : http://www.cs.plattsburgh.edu/~salva...bin_demo1.html
Happy programming!
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: Sauron911 is an unknown quantity at this point 
Solved Threads: 0
Sauron911 Sauron911 is offline Offline
Newbie Poster

Re: Binary Operation help.

 
0
  #3
Nov 7th, 2008
Hello,

It doesn't help. What i want to do is convert res into binary and find how many zeros it has.. and then print it in the main.. saying it has X amount of zeros.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,021
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 299
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: Binary Operation help.

 
0
  #4
Nov 7th, 2008
Well, try this one http://www.is.wayne.edu/olmt/binary/page3.htm
Don't you see a pattern that you can use to count the zeros?
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,117
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 282
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Binary Operation help.

 
0
  #5
Nov 8th, 2008
No wonder those links don't help. They have nothing to do with the problem.

First off, res is already binary. If you know the shift operator (<<), that makes it easy to count the 0's. Look it up and see what you come up with.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC