Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6777683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:10:38+00:00 2026-05-26T16:10:38+00:00

I have a program that I have written that has 26 int arrays representing

  • 0

I have a program that I have written that has 26 int arrays representing the letters of the alphabet. They each contain 5 binary numbers that represent Lights that will be lit up on a display. What I need to do is to convert a string into the binary data. For example, If you look at the code below:

int B[] = {B1111111, B1001001, B1001001, B0110110, B0000000};
int O[] = {B0111110, B1000001, B1000001, B0111110, B0000000};

So if the string was “BOB” I need it to create an array that looks something like this:

int CurrentWord[] = {B1111111, B1001001, B1001001, B0110110, B0000000, B0111110, B1000001, B1000001, B0111110, B0000000, B1111111, B1001001, B1001001, B0110110, B0000000};

I can see maybe doing this with a bunch of switches, but there must be a better way.

PS, I know my code is in objective c, I am looking to do this in C#

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:10:38+00:00Added an answer on May 26, 2026 at 4:10 pm

    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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a program that makes sure each cookie has more than 5
I have a PHP program that has been written keeping in mind a single
I have a website cgi-bin program that is written in c++. Unfortunately the website
I have written a program that will etablish a network connection with a remote
I have written a program that uses qhttp to get a webpage. This works
Below I have written a sample program that I have written to learn about
I have written a java program that is actually works as a gui to
I have written a c# program that calls a c++ dll that echoes the
I have written an ActionScript client program that tries to connect to a local
I have a program written in VB.Net (Visual Studio 2008) that uses a DLL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.