{"id":79,"date":"2009-05-01T11:40:41","date_gmt":"2009-05-01T09:40:41","guid":{"rendered":"http:\/\/blog.ansuz.nl\/?p=79"},"modified":"2009-05-03T18:49:51","modified_gmt":"2009-05-03T16:49:51","slug":"colors-and-bitwise-operators","status":"publish","type":"post","link":"http:\/\/blog.ansuz.nl\/index.php\/2009\/05\/01\/colors-and-bitwise-operators\/","title":{"rendered":"Colors and bitwise operators"},"content":{"rendered":"<p>I found this very interesting post called &#8220;<a href=\"http:\/\/www.tracestatement.com\/2007\/11\/hex-colors-bitwise-operators.html\" target=\"_blank\">Hex colors &amp; bitwise operators<\/a>&#8221; on www.tracestatement.com a while back and I&#8217;ve been meaning to blog about it.<\/p>\n<div id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">ActionScript<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"actionscript\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #808080;font-style: italic\">\/\/ From hex value to r,g,b values<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">var<\/span> hex:uint = 0xFF8811;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">var<\/span> r:uint = rgb <span style=\"color: #66cc66\">&amp;<\/span>gt;<span style=\"color: #66cc66\">&amp;<\/span>gt; <span style=\"color: #cc66cc\">16<\/span>;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">var<\/span> g:uint = rgb <span style=\"color: #66cc66\">&amp;<\/span>gt;<span style=\"color: #66cc66\">&amp;<\/span>gt; <span style=\"color: #cc66cc\">8<\/span> <span style=\"color: #66cc66\">&amp;<\/span>amp; 0xFF;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">var<\/span> b:uint = rgb <span style=\"color: #66cc66\">&amp;<\/span>amp; 0xFF;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #808080;font-style: italic\">\/\/From r,g,b values to hex value<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">hex = <span style=\"color: #66cc66\">&#040;<\/span>r <span style=\"color: #66cc66\">&amp;<\/span>lt;<span style=\"color: #66cc66\">&amp;<\/span>lt; <span style=\"color: #cc66cc\">16<\/span><span style=\"color: #66cc66\">&#041;<\/span> <span style=\"color: #66cc66\">|<\/span> <span style=\"color: #66cc66\">&#040;<\/span>g <span style=\"color: #66cc66\">&amp;<\/span>lt;<span style=\"color: #66cc66\">&amp;<\/span>lt; <span style=\"color: #cc66cc\">8<\/span><span style=\"color: #66cc66\">&#041;<\/span> <span style=\"color: #66cc66\">|<\/span> b;<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>This tiny bit of code allows you to rapidly subtract the Red, Green and Blue values from a hexadecimal colour code. Once you have the R, G, B bits you can then manipulate them and once done convert them back to a single Hex value.<\/p>\n<p>An important thing to remember is <a href=\"http:\/\/en.wikipedia.org\/wiki\/Bit_mask\" target=\"_blank\">bitmasking<\/a>, this can be used to switch a set of bits either on or off.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>I found this very interesting post called &#8220;Hex colors &amp; bitwise operators&#8221; on www.tracestatement.com a while back and I&#8217;ve been meaning to blog about it. &lt; View plain text &gt; ActionScript \/\/ From hex value to r,g,b values var hex:uint &hellip; <a href=\"http:\/\/blog.ansuz.nl\/index.php\/2009\/05\/01\/colors-and-bitwise-operators\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,8],"tags":[74,75,57,72,58,73],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-actionscript2","category-actionscript-30","tag-bit","tag-bitwise","tag-color","tag-colors","tag-colour","tag-colours"],"_links":{"self":[{"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":1,"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":80,"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/posts\/79\/revisions\/80"}],"wp:attachment":[{"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/categories?post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.ansuz.nl\/index.php\/wp-json\/wp\/v2\/tags?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}