![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 1
Rep Power: 0
![]() |
Hi,
I am trying to write the a program as follows: isLess - if x < y then return 1, else return 0. Example: isLess(4,5) = 1. Legal operations are ! ~ & ^ | + << >> I cannot use loops or logical operators. This is running on a 32 bit system. My code so far is: int isLess(int x, int y) { return !((y + (~x + 1) ) >> 31) ; } It seems to work for all numbers except for negative numbers, example: Test isLess(1768011938[0x6961b8a2],-2147483644[0x80000004]) failed. Gives 1[0x1]. Should be 0[0x0] Does anyone see anything obviously wrong with my code? It's driving me crazy! Thanks, |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|