byteMaskString static method

dynamic byteMaskString(
  1. String c,
  2. String str
)

Convert a string of 8 characters into a byte where the positions containing character c will have their bit set. For example, c = 'x', str = "x1xx0000" will return 0b10110000.

Implementation

static dynamic byteMaskString(String c, String str) {
  int str0 = str[0] == c ? 1 : 0;
  int str1 = str[1] == c ? 1 : 0;
  int str2 = str[2] == c ? 1 : 0;
  int str3 = str[3] == c ? 1 : 0;
  int str4 = str[4] == c ? 1 : 0;
  int str5 = str[5] == c ? 1 : 0;
  int str6 = str[6] == c ? 1 : 0;
  int str7 = str[7] == c ? 1 : 0;

  return ((str0 << 7) |
      (str1 << 6) |
      (str2 << 5) |
      (str3 << 4) |
      (str4 << 3) |
      (str5 << 2) |
      (str6 << 1) |
      (str7 << 0));
}