30
1
using System;
2
3
public class Program
4
{
5
public static void Main()
6
{
7
Test(0);
8
Test(1);
9
Test(64);
10
Test(65);
11
Test(-100);
12
Test(-101);
13
Test(102);
14
Test(888887);
15
Test(int.MaxValue);
16
Test(int.MinValue);
17
}
18
19
private static void Test(int x)
20
{
21
int y = Calculate(x);
22
Console.WriteLine("Input: {0}; Output: {1};", x, y);
23
}
24
25
26
private static int Calculate(int x)
27
{
28
return ((-x ^ x) >> 31) + 1;
29
}
30
}
Cached Result