fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. private static void AddMessage(Tuple<string, string> message)
  7. {
  8. Console.WriteLine("{0}, {1}", message.Item1, message.Item2);
  9. }
  10.  
  11. public static void Main()
  12. {
  13. byte val = 176;
  14.  
  15. for (int i = 0; i <= 7; i++)
  16. {
  17. if ((val & (1 << i)) != 0)
  18. AddMessage(messageByBitIndex[i]);
  19. }
  20. }
  21.  
  22. private static Tuple<string, string>[] messageByBitIndex =
  23. {
  24. Tuple.Create("1", "А1"), // 0
  25. Tuple.Create("1", "А2"), // 1
  26. Tuple.Create("2", "Б1"), // 2
  27. Tuple.Create("2", "Б2"), // 3
  28. Tuple.Create("1", "АА1"), // 4
  29. Tuple.Create("1", "АА2"), // 5
  30. Tuple.Create("2", "ББ1"), // 6
  31. Tuple.Create("2", "ББ2"), // 7
  32. };
  33. }
Success #stdin #stdout 0.04s 23952KB
stdin
Standard input is empty
stdout
1, АА1
1, АА2
2, ББ2