BorislavBorisov

30.04.We All Love Bits string bits

Feb 9th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using System;
  2. class FighterAttack
  3. {
  4.     static void Main()
  5.     {
  6.         int N = int.Parse(Console.ReadLine());
  7.         string str = "";
  8.  
  9.         for (int i = 0; i < N; i++)
  10.         {
  11.             int P = int.Parse(Console.ReadLine());
  12.             while (P > 0)
  13.             {
  14.                 if ((P & 1) != 0)
  15.                 {
  16.  
  17.                     str += '1';
  18.                 }
  19.                 else
  20.                 {
  21.                     str += '0';
  22.                 }
  23.                 P >>= 1;
  24.             }
  25.             Console.WriteLine(Convert.ToInt32(str, 2));
  26.             str = "";
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment