Skip to content

Instantly share code, notes, and snippets.

@unilecs
Last active February 25, 2019 05:53
Show Gist options
  • Save unilecs/28011b6269381699995e690901d0ad25 to your computer and use it in GitHub Desktop.
Save unilecs/28011b6269381699995e690901d0ad25 to your computer and use it in GitHub Desktop.
Задача. Побитовая арифметика
using System;
public class Program
{
public static int GetAnswerWithTest(int k, int n)
{
int result = k << n;
int testResult = (int)(k * Math.Pow(2, n));
if (result != testResult)
{
throw new Exception("Error!");
}
return result;
}
public static void Main()
{
Console.WriteLine("UniLecs");
Console.WriteLine(string.Format("Answer = {0}", GetAnswerWithTest(1, 4))); // 16
Console.WriteLine(string.Format("Answer = {0}", GetAnswerWithTest(3, 4))); // 48
Console.WriteLine(string.Format("Answer = {0}", GetAnswerWithTest(3, 5))); // 95
Console.WriteLine(string.Format("Answer = {0}", GetAnswerWithTest(4, 6))); // 256
Console.WriteLine(string.Format("Answer = {0}", GetAnswerWithTest(10, 10))); // 10240
Console.WriteLine(string.Format("Answer = {0}", GetAnswerWithTest(1000, 20))); // 1048576000
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment