DonJabone

BinaryDigits

Dec 5th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. class ThirdTask
  9. {
  10.     static void Main()
  11.     {
  12.         StringBuilder firstSB = new StringBuilder();
  13.         StringBuilder secondSB = new StringBuilder();
  14.         StringBuilder thirdSB = new StringBuilder();
  15.         StringBuilder fourthSB = new StringBuilder();
  16.         int number = int.Parse(Console.ReadLine());
  17.         for (int i = 15; i >= 0; i--)
  18.         {
  19.             int mask = 1 << i;
  20.             int numberAndMask = number & mask;
  21.             int bit = numberAndMask >> i;
  22.             if (bit == 1)
  23.             {
  24.                 firstSB.Append(".#.");
  25.                 secondSB.Append("##.");
  26.                 thirdSB.Append(".#.");
  27.                 fourthSB.Append("###");
  28.             }
  29.             else
  30.             {
  31.                 firstSB.Append("###");
  32.                 secondSB.Append("#.#");
  33.                 thirdSB.Append("#.#");
  34.                 fourthSB.Append("###");
  35.             }
  36.             if (i != 0)
  37.             {
  38.                 firstSB.Append(".");
  39.                 secondSB.Append(".");
  40.                 thirdSB.Append(".");
  41.                 fourthSB.Append(".");
  42.             }
  43.            
  44.         }
  45.         Console.WriteLine(firstSB.ToString());
  46.         Console.WriteLine(secondSB.ToString());
  47.         Console.WriteLine(thirdSB.ToString());
  48.         Console.WriteLine(fourthSB.ToString());
  49.  
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment