.NET Fiddle

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		Test(0);
		Test(1);
		Test(64);
		Test(65);
		Test(-100);
		Test(-101);
		Test(102);
		Test(888887);
		Test(int.MaxValue);
		Test(int.MinValue);
	}
	
	private static void Test(int x)
	{
		int y = Calculate(x);
		Console.WriteLine("Input: {0}; Output: {1};", x, y);
	}
	
	
	private static int Calculate(int x)
	{
		return ((-x ^ x) >> 31) + 1;
	}
}
;