This is a job for an array of arrays.
Objective C
int[][] map = new int[26][];
map[0] = {B0000000, B0000000, B0000000, B0000000, B0000000}; // Letter "A"
map[1] = {B1111111, B1001001, B1001001, B0110110, B0000000}; // Letter "B"
... Populate the array ...
To do the lookup, get the ASCII value of the upper-case character (which will be from 64 to 90) and subtract 64, and use that as your array index:
char c = 'B'; // char can be treated as an int
int index = toupper(c) - 'A'; // See the link above for an explanation
int[] result = map[ascii]; // Returns the map for "B"
Obviously, to finish this off, you'd need to loop over all chars and copy each result to your output.
NSString *myString = [NSString stringWithString:@"Tanner"];
unichar c;
for(int i=0; i<[myString length]; i++) {
c = [myString characterAtIndex:i];
// char can be treated as an int
int index = toupper(c) - 'A'; // See the link above for an explanation
int[] result = map[ascii]; // Returns the map for "B"
... Append the result to a list of results ...
}
Please excuse any Objective-C syntax issues, the question is tagged C#, so I had to adapt to Objective-C.
Update: C#
This is way easier in C#. The concept remains the same, but the code is much neater.
public static class Lights
{
public static byte[] Encode(string input)
{
// Convert to ASCII values, get the map, and flatten it:
return input.ToUpper().SelectMany(c => map[c-65]).ToArray();
}
// Note: C# does not have Binary Literals, so here's an alternative:
private const byte B0000000 = 0, B0000001 = 1, B0000010 = 2, B0000011 = 3, B0000100 = 4, /* ETC */ B1111111 = 127, B1001001 = 73, B0110110 = 102, B0111110 = 126, B1000001 = 129;
// Create the map:
private static byte[][] map = new []{
/* A */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* B */ new[]{ B1111111, B1001001, B1001001, B0110110, B0000000 },
/* C */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* D */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* E */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* F */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* G */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* H */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* I */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* J */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* K */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* L */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* M */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* N */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* O */ new[]{ B0111110, B1000001, B1000001, B0111110, B0000000 },
/* P */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* Q */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* R */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* S */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* T */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* U */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* V */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* W */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* X */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* Y */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
/* Z */ new[]{ B0000000, B0000000, B0000000, B0000000, B0000000 },
};
}
Here's how to get the results:
byte[] lights = Lights.Encode("BOB");
A couple of cool things to note: C# lets you iterate a string as if it was a char array, and it lets you perform char math, so the code is super-simple. Yay!