wu :: forums
« wu :: forums - Add 32-bit Numbers »

Welcome, Guest. Please Login or Register.
May 19th, 2024, 9:29am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Eigenray, ThudnBlunder, SMQ, Icarus, towr, william wu, Grimbal)
   Add 32-bit Numbers
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Add 32-bit Numbers  (Read 1274 times)
william wu
wu::riddles Administrator
*****





   
WWW

Gender: male
Posts: 1291
Add 32-bit Numbers  
« on: Feb 4th, 2003, 9:37pm »
Quote Quote Modify Modify

From Usenet:
 
You have to add three 32-bit two's complement numbers using only one '+'. Other legal (C) operators are ! ~ &  
^ | << >> but those can be used more than once. You may at most use 17 operators.
IP Logged


[ wu ] : http://wuriddles.com / http://forums.wuriddles.com
Jeremiah Smith
Full Member
***



Beep!

   


Posts: 172
Re: Add 32-bit Numbers  
« Reply #1 on: Feb 8th, 2003, 4:15pm »
Quote Quote Modify Modify

Are parentheses considered operators for this problem?
 
I can already see that I can't make any temporary variables, since = (assignment) is an operator itself and isn't on the list...
IP Logged
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: Add 32-bit Numbers  
« Reply #2 on: May 29th, 2004, 3:29pm »
Quote Quote Modify Modify

int add3(int a, int b, int c){
    return (a^b^c) + ((a&(b|c)|b&c)<<1);
}
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board