{"id":5546,"date":"2024-06-08T03:00:00","date_gmt":"2024-06-08T07:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=5546"},"modified":"2024-05-29T19:33:12","modified_gmt":"2024-05-29T23:33:12","slug":"why-dos-only-has-16-colors","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=5546","title":{"rendered":"Why DOS only has 16 colors"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"5546\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p>If you\u2019ve used <code>conio<\/code> functions to write FreeDOS programs, you may have noticed that you have a color palette of just 16 text colors, and 8 background colors. You see this \u201c16 colors\u201d limitation repeated in other places, too. For example, while the Linux console actually supports a wide range of text colors using \u201cescape sequences,\u201d your terminal app only supports a basic palette of 16 colors.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"400\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2024\/05\/16colors.png\" alt=\"\" class=\"wp-image-5547\"\/><\/figure>\n\n\n\n<p>The origins of this range of limited colors goes back to how color was defined on early display devices. I\u2019ll use DOS as an example, since that\u2019s the color palette I grew up with.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ibm-pc-and-color-text\">IBM PC and color text<\/h2>\n\n\n\n<p>When the IBM Personal Computer 5150 came out in 1981, the first model supported only monochrome displays: \u201cwhite on black,\u201d although the green display in use at the time meant you really had \u201cgreen on black.\u201d Soon after, IBM provided an updated model with a new display interface: the IBM 5153 color display, which used a new IBM Color Graphics Adapter, or \u201cCGA.\u201d And it\u2019s because of the original CGA that DOS inherited its 16 color palette.<\/p>\n\n\n\n<p>Colors on a computer monitor are just a combination of three colors: red, green, and blue. If you mix equal amounts of red, green, and blue, you get white. Mix just red and green, and you get yellow. Just green and blue, you get aquamarine (named \u201ccyan\u201d at the time). Red and blue give you purple (called \u201cmagenta\u201d). Without any colors, you get black.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"665\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2024\/05\/rgb-circles.png\" alt=\"\" class=\"wp-image-5548\"\/><\/figure>\n\n\n\n<p>The IBM CGA display represented colors by lighting up tiny red, green, and blue phosphor dots on the inside of the computer screen. Your modern display does the same thing, except with tiny LED red, green, and blue LED lights.<\/p>\n\n\n\n<p>With these three \u201cbase\u201d colors, you can turn each red, green, and blue \u201cdot\u201d on at full blast, or leave them off, to create one of eight different colors. I\u2019ll represent the red, green, and blue lights in order as <code>RGB<\/code> (for \u201cRed, Green, Blue\u201d) and each value is either <code>1<\/code> (\u201con\u201d) or <code>0<\/code> (\u201coff\u201d). This gives you a 3-bit binary pattern that represents <code>RGB<\/code>:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table style=\"width:99%\">\n<tr>\n<td style=\"background-color:#000;width:20%\">\n<\/td>\n<td style=\"width:80%\">\n000\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#00f;width:20%\">\n<\/td>\n<td style=\"width:80%\">\n001\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#0f0;width:20%\">\n<\/td>\n<td style=\"width:80%\">\n010\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#0ff;width:20%\">\n<\/td>\n<td style=\"width:80%\">\n011\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#f00;width:20%\">\n<\/td>\n<td style=\"width:80%\">\n100\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#f0f;width:20%\">\n<\/td>\n<td style=\"width:80%\">\n101\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#ff0;width:20%\">\n<\/td>\n<td style=\"width:80%\">\n110\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#fff;width:20%\">\n<\/td>\n<td style=\"width:80%\">\n111\n<\/td>\n<\/tr>\n<\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"double-the-colors\">Double the colors<\/h2>\n\n\n\n<p>But that\u2019s just a simple mixing of red, green, and blue &#8211; with each value either fully \u201con\u201d or fully \u201coff.\u201d You can actually double the number of colors if you add a fourth bit: an \u201cintensity\u201d bit, giving you <code>iRGB<\/code> (the <code>i<\/code> stands for \u201cintensity\u201d). If the intensity bit is <code>1<\/code>, you get full brightness for each red, green, and blue dot that is turned on. If the bit is <code>0<\/code>, you get some midrange brightness for the <code>RGB<\/code> dots:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table style=\"width:99%\">\n<tr>\n<td style=\"background-color:#000;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0000\n<\/td>\n<td style=\"background-color:#000;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1000\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#006;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0001\n<\/td>\n<td style=\"background-color:#00f;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1001\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#060;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0010\n<\/td>\n<td style=\"background-color:#0f0;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1010\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#066;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0011\n<\/td>\n<td style=\"background-color:#0ff;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1011\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#600;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0100\n<\/td>\n<td style=\"background-color:#f00;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1100\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#606;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0101\n<\/td>\n<td style=\"background-color:#f0f;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1101\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#660;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0110\n<\/td>\n<td style=\"background-color:#ff0;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1110\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#666;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0111\n<\/td>\n<td style=\"background-color:#fff;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1111\n<\/td>\n<\/tr>\n<\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"adjusting-the-colors\">Adjusting the colors<\/h2>\n\n\n\n<p>But this isn\u2019t actually 16 colors! With the <code>iRGB<\/code> color scheme, only the red, green, and blue lights get adjusted. If a bit is <code>0<\/code>, nothing gets displayed anyway. That means that <code>0000<\/code> (black) and <code>1000<\/code> (black) are the same black.<\/p>\n\n\n\n<p>To adjust this, the IBM PC actually used a <em>modified<\/em> <code>iRGB<\/code> color scheme, where each of the <code>RGB<\/code> values was set to zero, one-third, two-thirds, and full brightness levels. If the intensity bit is <code>0<\/code>, then each <code>1<\/code> value for <code>RGB<\/code> is set to a two-thirds value, and each <code>0<\/code> value remains off. If the intensity bit is <code>1<\/code>, then each <code>1<\/code> value for <code>RGB<\/code> shifts to full brightness, and each <code>0<\/code> value displays at one-third brightness. This gives a true palette of 16 unique colors:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table style=\"width:99%\">\n<tr>\n<td style=\"background-color:#000;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0000\n<\/td>\n<td style=\"background-color:#555;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1000\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#00a;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0001\n<\/td>\n<td style=\"background-color:#55f;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1001\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#0a0;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0010\n<\/td>\n<td style=\"background-color:#5f5;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1010\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#0aa;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0011\n<\/td>\n<td style=\"background-color:#5ff;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1011\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#a00;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0100\n<\/td>\n<td style=\"background-color:#f55;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1100\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#a0a;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0101\n<\/td>\n<td style=\"background-color:#f5f;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1101\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#aa0;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0110\n<\/td>\n<td style=\"background-color:#ff5;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1110\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#aaa;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0111\n<\/td>\n<td style=\"background-color:#fff;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1111\n<\/td>\n<\/tr>\n<\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"all-the-colors-of-the-rainbow\">All the colors of the rainbow<\/h2>\n\n\n\n<p>Unfortunately, this isn\u2019t a perfect representation of colors. If you remember your 4th grade colors, you know that the colors of the rainbow are represented by the acronym, <code>ROYGBIV<\/code>, which means red, orange, yellow, green, blue, indigo, and violet. And while not all of those colors are represented perfectly in the 16 colors, we have similar colors for most of these. The only color that\u2019s really missing in the 16-color palette is orange.<\/p>\n\n\n\n<p>To provide an orange hue, the IBM PC modified the <code>iRGB<\/code> definition for 0110, giving the <code>R<\/code> value a two-thirds brightness and the <code>G<\/code> color a one-third brightness. This generates a color that\u2019s pretty close to orange:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table style=\"width:99%\">\n<tr>\n<td style=\"background-color:#000;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0000\n<\/td>\n<td style=\"background-color:#555;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1000\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#00a;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0001\n<\/td>\n<td style=\"background-color:#55f;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1001\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#0a0;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0010\n<\/td>\n<td style=\"background-color:#5f5;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1010\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#0aa;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0011\n<\/td>\n<td style=\"background-color:#5ff;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1011\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#a00;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0100\n<\/td>\n<td style=\"background-color:#f55;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1100\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#a0a;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0101\n<\/td>\n<td style=\"background-color:#f5f;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1101\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#a50;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0110\n<\/td>\n<td style=\"background-color:#ff5;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1110\n<\/td>\n<\/tr>\n<tr>\n<td style=\"background-color:#aaa;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n0111\n<\/td>\n<td style=\"background-color:#fff;width:20%\">\n<\/td>\n<td style=\"width:30%\">\n1111\n<\/td>\n<\/tr>\n<\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"bits-and-bytes\">Bits and bytes<\/h2>\n\n\n\n<p>Using this modified <code>iRGB<\/code> color scheme uses only 4 bits, but a full byte can store 8 bits. IBM\u2019s CGA used a full byte to store both text and background colors, using the first 4 bits for the background color and the last 4 bits for the text color. You\u2019d think this gives you 16 colors for the background color, but it doesn\u2019t. That\u2019s because IBM made one final change.<\/p>\n\n\n\n<p>The 8th bit was reserved for a special attribute: blinking text. With the \u201cblink\u201d bit set, text blinked on the screen &#8211; a typical way to display critical error messages. With one byte, DOS programs could set all attributes at once: text color, background color, and whether or not the text should blink. Thus, CGA defined 1 bit for the \u201cblink\u201d bit (<code>B<\/code>), 3 bits for the background color (<code>b<\/code>), and 4 bits for the text color (<code>t<\/code>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>B b b b t t t t<\/code><\/pre>\n\n\n\n<p>Unfortunately, this meant that background colors were limited to just 8 colors, while text could have all 16 colors. Some third-party graphics cards in the early 1990s supported modifying the blink bit to support bright background colors, but most traditional DOS programs were limited to combinations of 16 text colors on 8 background colors. This limited palette continues to this day.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever wondered why DOS text only comes in 16 colors and 8 background colors?<\/p>\n","protected":false},"author":33,"featured_media":5547,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[340,106,5],"tags":[267,316],"class_list":["post-5546","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-freedos","category-history","category-linux","tag-freedos","tag-history"],"modified_by":"Jim Hall","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/5546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5546"}],"version-history":[{"count":2,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/5546\/revisions"}],"predecessor-version":[{"id":5550,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/5546\/revisions\/5550"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/5547"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}