- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication49
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Введите 16-ричное число(не более 32 знаков)");
string s = Console.ReadLine();
string result = "";
string t = "123456789abcdef0";
int i = 0;
char[] a = new char[32];
a = s.ToCharArray();
char[] b = new char[16];
b = t.ToCharArray();
while (i<a.Length)
{
if (a[i] != b[0]) ; else result += "0001";
if (a[i] != b[1]) ; else result += "0010";
if (a[i] != b[2]) ; else result += "0011";
if (a[i] != b[3]) ; else result += "0100";
if (a[i] != b[4]) ; else result += "0101";
if (a[i] != b[5]) ; else result += "0110";
if (a[i] != b[6]) ; else result += "0111";
if (a[i] != b[7]) ; else result += "1000";
if (a[i] != b[8]) ; else result += "1001";
if (a[i] != b[9]) ; else result += "1010";
if (a[i] != b[10]) ; else result += "1011";
if (a[i] != b[11]) ; else result += "1100";
if (a[i] != b[12]) ; else result += "1101";
if (a[i] != b[13]) ; else result += "1110";
if (a[i] != b[14]) ; else result += "1111";
if (a[i] != b[15]) ; else result += "0000";
i++;
};
Console.WriteLine("{0} в двоичном виде выглядит так {1}",s,result);
Console.ReadKey();
}
}
}
http://www.youtube.com/watch?v=QpHYbgLzri0
записанное в одну строчку правда..
"ConsoleApplication49" наводит на мысли о том, что код написался не с первой попытки. Автор явно старался сюда попасть:)
Попытка номер 49 :)
fixed