StringMash.com

7-segment display converter

Digits and letters to lit segments and byte codes, and codes back to digits.

Conversion
5 characters
Updates as you type
Segmentsbc abdeg+DP abcdg bcfg
Hex (gfedcba)0x06 0xDB 0x4F 0x66
Binary00000110 11011011 01001111 01100110
Decimal6 219 79 102
C array{ 0x06, 0xDB, 0x4F, 0x66 }
Swap the boxes to decode byte codes

Show the steps
  1. Each character lights some of the segments a to g: a is the top bar, then clockwise b, c, d, e, f, with g across the middle.
  2. In gfedcba order, a is the lowest bit (0x01) and g is 0x40. The decimal point takes the eighth bit, 0x80.

Using the converter

Type digits or a short word. You get one byte per digit, ready to paste into a lookup table, and a drawing of how the display will look. A full stop after a digit lights its decimal point, so 12.34 still takes four digits.

Pick the bit order your wiring uses and whether the display is common cathode or common anode. Swap the boxes to go the other way: paste codes such as 0x3F 0x06 and read the digits they draw.

How the segments are named

The seven bars are labelled a to g. Start at the top bar, a, and go clockwise round the outside, ending with f on the upper left. The middle bar is g. The decimal point, DP, is sometimes called the eighth segment.

One byte holds the whole state of a digit. The two common bit layouts are gfedcba and abcdefg. In gfedcba, a is the lowest bit, so 0x06 lights b and c and shows a 1. This tool puts DP in the top bit, 0x80, in both layouts.

7-segment hex code chart

Digits 0 to 9 and hex A to F. Common-anode codes are the gfedcba codes inverted.
ShowsSegmentsgfedcbaabcdefgCommon anode
0abcdef0x3F0x7E0xC0
1bc0x060x300xF9
2abdeg0x5B0x6D0xA4
3abcdg0x4F0x790xB0
4bcfg0x660x330x99
5acdfg0x6D0x5B0x92
6acdefg0x7D0x5F0x82
7abc0x070x700xF8
8abcdefg0x7F0x7F0x80
9abcdfg0x6F0x7B0x90
Aabcefg0x770x770x88
bcdefg0x7C0x1F0x83
Cadef0x390x4E0xC6
dbcdeg0x5E0x3D0xA1
Eadefg0x790x4F0x86
Faefg0x710x470x8E

Common cathode or common anode?

In a simple LED package all the cathodes, or all the anodes, are joined to one common pin. On a common-cathode display you drive a segment pin high to light it. On a common-anode display you pull it low, so every bit in the code is flipped.

Not sure? Check the datasheet. Wrong wiring is easy to spot, because the display lights the gaps around the digit and leaves the digit itself dark.

Letters on seven segments

Hex digits B and D are shown in lowercase, as b and d, so they are not confused with 8 and 0. The 6 keeps its top bar for the same reason, or it would look like a b.

Many other letters fit, though some only in lowercase (n is one). A few clash with digits: I looks like 1, S like 5 and Z like 2. Some letters have no usable shape at all. K is the classic example. The converter leaves those out and tells you.

Questions

What is the 7-segment code for 0?

0x3F in gfedcba order on a common-cathode display. That lights every segment except g, the middle bar.

Why does my display show the wrong segments?

Usually the bit order is the other way round from your code, or the display is common anode and needs inverted codes. Try the other settings and compare.

Can it show a colon for a clock?

Clock colons are separate LEDs on most modules, not part of a digit, so the converter skips colons. 12:45 comes out as four digits.

Sources

Added and reviewed . What's new