Problem of the Day
A new programming or logic puzzle every Mon-Fri

7 Segment Alphabet

Happy happy Monday!

Today's programming problem is for those that love to tinker with hardware. Your goal is to create a function that converts the letters A-Z and 0-9 to their 7 segment display counterpart. Your function should return the binary values needed for the output (alternatively you can just pretty print 7 segment looking characters). You may find this image helpful.

7 segment truth table

Note: Some characters may be duplicated such as "U" and "V"

Permalink: http://problemotd.com/problem/7-segment-alphabet/

Comments:

  • Anonymous - 9 years, 11 months ago

    Shouldn't there be more than one segment illuminated for a 1? I would think it's be "b" and "c"?

    reply permalink

  • Max Burstein - 9 years, 11 months ago

    You're definitely right. That image has a mistake. c should also be lit up.

    reply permalink

  • Anonymous - 9 years, 11 months ago

    Seems like a crappy solution but there is always :

    private bool[] GetSevenSegmentFlags(char c)
        {
            var flags = new bool[7];
    
            switch (c)
            {
                case 'a' :
                case 'A':
                    flags[0] = true;
                    flags[1] = true;
                    flags[2] = true;
                    flags[4] = false;
                    flags[5] = true;
                    flags[6] = true;
                    flags[7] = false;
                    break;
            }
    
            return flags;
    }
    

    Is there a more elegant way to do this?

    reply permalink

  • David - 8 years, 11 months ago

    A bit sadly, this is a rubber hits the road type of problem. At some point you need to define which segments are associated with each character. You might prefer assigning a number and using some bit magic to get the display mask, but then you really just change the look of the problem instead.

    reply permalink

Content curated by @MaxBurstein