Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.16 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. namespace ConsoleApp4
  8. {
  9.     class Program
  10.     {
  11.         static string ABCD(byte a, byte b, byte c, byte d)
  12.         {
  13.             int abcd = 0;
  14.             abcd = abcd | a;
  15.             abcd = abcd << 8;
  16.             abcd = abcd | b;
  17.             abcd = abcd << 8;
  18.             abcd = abcd | c;
  19.             abcd = abcd << 8;
  20.             abcd = abcd | d;
  21.             string output = Convert.ToString(abcd, 2);
  22.             return output;
  23.         }
  24.  
  25.         static string[] abcd(int abcd)
  26.         {
  27.             int[] ADCD = new int[4];
  28.             ADCD[3] = abcd & 0b11111111;
  29.             abcd = abcd >> 8;
  30.             ADCD[2] = abcd & 0b11111111;
  31.             abcd = abcd >> 8;
  32.             ADCD[1] = abcd & 0b11111111;
  33.             abcd = abcd >> 8;
  34.             ADCD[0] = abcd & 0b11111111;
  35.             string[] ABCDstring = new string[4];
  36.             ABCDstring[0] = Convert.ToString(ADCD[0], 2);
  37.             ABCDstring[1] = Convert.ToString(ADCD[1], 2);
  38.             ABCDstring[2] = Convert.ToString(ADCD[2], 2);
  39.             ABCDstring[3] = Convert.ToString(ADCD[3], 2);
  40.             return ABCDstring;
  41.         }
  42.  
  43.         static string Round (int c)
  44.         {
  45.             string с_string = c.ToString();
  46.             string c_round = "";
  47.             for (int i = с_string.Length - 1; i >= 0; i--)
  48.             {
  49.                 c_round = c_round + с_string[i];
  50.             }
  51.             return c_round;
  52.         }
  53.  
  54.         static void Main(string[] args)
  55.         {
  56.             //Первое задание
  57.             Console.WriteLine(ABCD(3, 4, 5, 6));
  58.             string[] write = abcd(0b11000001000000010100000110);
  59.             for (int i = 0; i < write.Length; i++)
  60.             {
  61.                 Console.WriteLine(write[i]);
  62.             }
  63.  
  64.             // Второе задание
  65.             int a = 0b101;
  66.             a = ~a;
  67.             string b = Convert.ToString(a, 2);
  68.             Console.WriteLine(b);
  69.  
  70.             //Третье задание
  71.             Console.WriteLine(Round(15));
  72.            
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement