| |
| Posted by Walter Bright in reply to Max Samukha | PermalinkReply |
|
Walter Bright
Posted in reply to Max Samukha
| On 9/10/2022 1:19 AM, Max Samukha wrote:
> Bit flags are easier to read as binary grouped in nibbles. For example:
>
> enum ubyte[16] ledDigits =
> [
> 0b0011_1111, // 0
> 0b0000_0110, // 1
> 0b0101_1011, // 2
> 0b0100_1111, // 3
> 0b0110_0110, // 4
> 0b0110_1101, // 5
> 0b0111_1101, // 6
> 0b0000_0111, // 7
> 0b0111_1111, // 8
> 0b0110_1111, // 9
> 0b0111_0111, // A
> 0b0111_1100, // b
> 0b0011_1001, // C
> 0b0101_1110, // d
> 0b0111_1001, // E
> 0b0111_0001, // F
> ];
>
> Those are the bit masks for a 7-segment display. Of course, you could define them by or'ing enum flags or translating into hex, or use a template, but that would be annoying.
Interesting that you brought up 7-segment display data, as I've actually written that stuff for embedded systems, and once again as a demonstration for the ABEL programming language.
A couple things about it:
1. The visual representation of the binary doesn't have any correlation with how the display looks.
2. It's a one-off. Once it's written, it never changes.
3. Writing it in hex isn't any difficulty for 10 entries.
A more compelling example would be, say, a character generator ROM, which I've also done.
0b01110
0b10001
0b11111
0b10001
0b10001
and you'll be doing a couple hundred of those at least. Wouldn't this be more appealing:
"
.XXX.
X...X
XXXXX
X...X
X...X
"
? Then write a trivial parser, and use CTFE to generate the binary data for the table. Of course, such a parser could be used over and over for other projects.
|