Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _5.BitsUp
- {
- using System;
- public class SetTo1TheBitsAtGivenPositionsInByteSequence
- {
- public static void Main(string[] args)
- {
- checked
- {
- int countN = int.Parse(Console.ReadLine());
- int step = int.Parse(Console.ReadLine());
- byte[] bytes = ReadNumbersFromInputAndWriteThemInArray(countN);
- int indexInSequence = 0;
- for (int i = 0; i < bytes.Length; i++)
- {
- byte num = bytes[i];
- for (int bit = 7; bit >= 0; bit--)
- {
- if ((indexInSequence % step == 1) || (step == 1 && indexInSequence > 0))
- {
- num |= (byte)(1 << bit);
- }
- indexInSequence++;
- }
- Console.WriteLine(num);
- }
- }
- }
- private static byte[] ReadNumbersFromInputAndWriteThemInArray(int count)
- {
- byte[] arr = new byte[count];
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = byte.Parse(Console.ReadLine());
- }
- return arr;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement