Tuesday, July 15, 2003

Gray is Light Black

To clarify what I said earlier about PC/DOS colors: Colors are specified in terms of red, green, blue and also something called "intensity". Each of these elements is represented by one bit. Intensity is the high-order bit. These four bits can conveniently be represented by a single hex digit, which is what the "color" command does. The following table is the same one I posted earlier, but also shows the binary IRGB values.

binary decimal hex name real RGB websafe
0000 0 0 Black 000000     000000    
0001 1 1 Blue 000080     000099    
0010 2 2 Green 008000     009900    
0011 3 3 Aqua 008080     009999    
0100 4 4 Red 800000     990000    
0101 5 5 Purple 800080     990099    
0110 6 6 Yellow 808000     999900    
0111 7 7 White c0c0c0     cccccc    
1000 8 8 Gray 808080     999999    
1001 9 9 Light Blue 0000ff     0000ff    
1010 10 A Light Green 00ff00     00ff00    
1011 11 B Light Aqua 00ffff     00ffff    
1100 12 C Light Red ff0000     ff0000    
1101 13 D Light Purple ff00ff     ff00ff    
1110 14 E Light Yellow ffff00     ffff00    
1111 15 F Bright White ffffff     ffffff    

It should now be apparent that the only difference between "gray" (binary 1000) and "black" (binary 0000) is that gray has the intensity bit set.

(Note also that the names shown in the table are taken straight from the Win2K help system. If you type "color /?" those are the names you get. Why they choose to use "aqua" and "purple" for the colors that everybody's been called "cyan" and "magenta" for years is beyond me. I also take issue with what they chose to call "yellow" and "white".)

This also helps explain why DOS wouldn't let you use "light" or "intense" background colors in text modes. The foreground and background colors were packed into a single 8-bit byte. Now, this seems like it would've been fine, since each color is 4 bits. But they also wanted to be able to make the text blink. In order to make room for a "blink" bit, the background color has no intensity bit. Thankfully, the NT "color" command does not support blinking, so we get the full 16 background colors.

Finally, in monochrome mode, the "color" bits were used to control things like reversed and underlined text. There was not actually support for underlining in color text modes, so technically I'm cheating by using underlined links on the menu here.

Comments: