-
Notifications
You must be signed in to change notification settings - Fork 1
/
BitKiller.cs
61 lines (58 loc) · 1.68 KB
/
BitKiller.cs
1
2
3
4
5
6
7
8
9
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
class BitKiller
{
static void Main()
{
int n = int.Parse(Console.ReadLine());
int step = int.Parse(Console.ReadLine());
List<string> digits = new List<string>();
int startBit = 6;
string result = "";
for (int i = 0; i < n; i++)
{
int number = int.Parse(Console.ReadLine());
for (int j = 7; j >= 0; j--)
{
if (j != startBit)
{
int bit = (number & (1 << j)) >> j;
digits.Add(Convert.ToString(bit));
}
else
{
startBit -= step;
}
if (digits.Count == 8)
{
foreach (string digit in digits)
{
result = result + "" + digit;
}
int numberToPrint = Convert.ToInt32(result, 2);
Console.WriteLine(numberToPrint);
digits.Clear();
result = "";
}
}
if (startBit < 0)
{
startBit += 8;
}
}
if (digits.Count != 8 && digits.Count != 0)
{
while(digits.Count != 8)
{
digits.Add("0");
}
foreach (string digit in digits)
{
result = result + "" + digit;
}
int numberToPrint = Convert.ToInt32(result, 2);
Console.WriteLine(numberToPrint);
digits.Clear();
}
}
}