-6

The title is a little misleading, but I don't know what else to call it. I have an array consisting of 2 values: int array [2];

One of the values will contain 0 and the other value won't contain 0. Without the use of an if statement and most preferably, no boolean expressions, I want to determine if array[0]; contains a 0 or not. If it doesn't contain 0, it should return 1, otherwise it should return 0.

I have tried dividing the first value by itself but a Division By Zero error can occur, and I have no other alternatives to my problem.

The format I am aiming for is like this:

array[check if zero index is 0];

EDIT: Examples of this are:

array[0] = 20; 
array[1] = 0;
array[check if zero index is 0]; // index is 1

array[0] = 0; 
array[1] = 73;
array[check if zero index is 0]; // index is 0;
Hayden
  • 407
  • 1
  • 6
  • 15

1 Answers1

1

this assumes 32bit int's

((static_cast<unsigned>(-(array[0]*array[0]))&(1ul<<31))>>31)
sp2danny
  • 7,488
  • 3
  • 31
  • 53