<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Javascript &#8211; RGB to Hexadecimal Color Converter</title>
	<atom:link href="http://trending.us/2009/01/07/javascript-rgb-to-hexadecimal-color-converter/feed/" rel="self" type="application/rss+xml" />
	<link>http://trending.us/2009/01/07/javascript-rgb-to-hexadecimal-color-converter/</link>
	<description></description>
	<lastBuildDate>Mon, 05 Dec 2011 01:30:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dehmers</title>
		<link>http://trending.us/2009/01/07/javascript-rgb-to-hexadecimal-color-converter/#comment-24427</link>
		<dc:creator>Dehmers</dc:creator>
		<pubDate>Sat, 17 Sep 2011 02:12:11 +0000</pubDate>
		<guid isPermaLink="false">http://popped.at/?p=35#comment-24427</guid>
		<description>&lt;strong&gt;Hello...&lt;/strong&gt;

My life,vist it http://www.gladyshardy.com/blog/zhangda/frog-prince-wedding-wedding-cake-toppers ,Thanks....</description>
		<content:encoded><![CDATA[<p><strong>Hello&#8230;</strong></p>
<p>My life,vist it <a href="http://www.gladyshardy.com/blog/zhangda/frog-prince-wedding-wedding-cake-toppers" rel="nofollow">http://www.gladyshardy.com/blog/zhangda/frog-prince-wedding-wedding-cake-toppers</a> ,Thanks&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TadWinetts</title>
		<link>http://trending.us/2009/01/07/javascript-rgb-to-hexadecimal-color-converter/#comment-24423</link>
		<dc:creator>TadWinetts</dc:creator>
		<pubDate>Wed, 14 Sep 2011 03:02:36 +0000</pubDate>
		<guid isPermaLink="false">http://popped.at/?p=35#comment-24423</guid>
		<description>&lt;strong&gt;Hello...&lt;/strong&gt;

My life,vist it http://yaplog.jp/promdresses/ ,Thanks....</description>
		<content:encoded><![CDATA[<p><strong>Hello&#8230;</strong></p>
<p>My life,vist it <a href="http://yaplog.jp/promdresses/" rel="nofollow">http://yaplog.jp/promdresses/</a> ,Thanks&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matildess</title>
		<link>http://trending.us/2009/01/07/javascript-rgb-to-hexadecimal-color-converter/#comment-24413</link>
		<dc:creator>Matildess</dc:creator>
		<pubDate>Fri, 09 Sep 2011 01:49:13 +0000</pubDate>
		<guid isPermaLink="false">http://popped.at/?p=35#comment-24413</guid>
		<description>&lt;strong&gt;Hello...&lt;/strong&gt;

My life,vist it http://xiangcaidress.lovelogger.com/pepe-le-pew-wedding-cake-topper/ ,Thanks....</description>
		<content:encoded><![CDATA[<p><strong>Hello&#8230;</strong></p>
<p>My life,vist it <a href="http://xiangcaidress.lovelogger.com/pepe-le-pew-wedding-cake-topper/" rel="nofollow">http://xiangcaidress.lovelogger.com/pepe-le-pew-wedding-cake-topper/</a> ,Thanks&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Lawrence</title>
		<link>http://trending.us/2009/01/07/javascript-rgb-to-hexadecimal-color-converter/#comment-20</link>
		<dc:creator>Charles Lawrence</dc:creator>
		<pubDate>Tue, 05 May 2009 19:58:05 +0000</pubDate>
		<guid isPermaLink="false">http://popped.at/?p=35#comment-20</guid>
		<description>&lt;p&gt;Hi John, thanks for visiting the site and commenting.&lt;/p&gt;&lt;p&gt;Your code sample has some errors (odd single/double quote marks) that I needed to correct, but this could easily be attributed to your text editor or the formatting my blog chose to use.&lt;/p&gt;&lt;p&gt;I tested your code(fixed) versus my code in a loop that did the test loop 1000 times. In Firefox 3.0 and Safari 4 beta(the 2 browsers I tested in), my original code is generally faster than your sample. Additionally, the regex match does better validation about whether or not the string being passed in is an rgb value or not.&lt;/p&gt;&lt;p&gt;In Firefox 3.0.10 on Mac, running the test 10 times: &lt;br/&gt;(My code :: Your code)&lt;br/&gt;22 :: 26&lt;br/&gt;21 :: 25&lt;br/&gt;20 :: 27&lt;br/&gt;21 :: 26&lt;br/&gt;19 :: 25&lt;br/&gt;20 :: 27&lt;br/&gt;19 :: 25&lt;br/&gt;21 :: 26&lt;br/&gt;19 :: 27&lt;br/&gt;22 :: 26&lt;/p&gt;&lt;p&gt;Safari 4(beta)&lt;br/&gt;9 :: 7&lt;br/&gt;8 :: 7&lt;br/&gt;7 :: 6&lt;br/&gt;8 :: 7&lt;br/&gt;6 :: 7&lt;br/&gt;8 :: 7&lt;br/&gt;7 :: 7&lt;br/&gt;8 :: 7&lt;br/&gt;7 :: 8&lt;br/&gt;7 :: 8&lt;/p&gt;&lt;p&gt;Safari has a very efficient js engine and for the most part, both of our versions are the same. But in the latest version of Firefox, my code is ~5 milliseconds faster. I would like to test this again in IE6/7/8 when I am able, but I suspect my version is faster there too. I would expect similar results as Safari for Chrome.&lt;/p&gt;&lt;p&gt;Here&#039;s the code I used for the test:&lt;br/&gt;//mine&lt;br/&gt;rgbhex = function(rgbval){&lt;br/&gt;	&lt;br/&gt;	var s = rgbval.match(/rgb\s*\x28((?:25[0-5])&#124;(?:2[0-4]\d)&#124;(?:[01]?\d?\d))\s*,\s*((?:25[0-5])&#124;(?:2[0-4]\d)&#124;(?:[01]?\d?\d))\s*,\s*((?:25[0-5])&#124;(?:2[0-4]\d)&#124;(?:[01]?\d?\d))\s*\x29/);&lt;/p&gt;&lt;p&gt;	if(s){ s=s.splice(1); }&lt;br/&gt;	if(s &amp;&amp; s.length==3){&lt;br/&gt;		var d=&#039;&#039;;&lt;br/&gt;		for(i in s){&lt;br/&gt;			var e=parseInt(s[i],10).toString(16);&lt;br/&gt;			e == &quot;0&quot; ? d+=&quot;00&quot;:d+=e;&lt;br/&gt;		} return &#039;#&#039;+d;&lt;br/&gt;	}else{ return rgbval; }&lt;br/&gt;	&lt;br/&gt;}&lt;/p&gt;&lt;p&gt;//his&lt;br/&gt;function rgbToHexColor(v) {&lt;br/&gt;	v = v.split(&#039;(&#039;)&lt;br/&gt;	&lt;br/&gt;	if(!v[1]) return v&lt;br/&gt;	&lt;br/&gt;	v = v[1].replace(/ /g, &#039;&#039;).replace(/\)/, &#039;&#039;)&lt;br/&gt;	v = v.split(&#039;,&#039;)&lt;br/&gt;	&lt;br/&gt;	for(i in v) {&lt;br/&gt;		v[i] = Number(v[i]).toString(16)&lt;br/&gt;		if(v[i].length==1) v[i] = &#039;0&#039; + v[i]&lt;br/&gt;	}&lt;br/&gt;	&lt;br/&gt;	return &#039;#&#039;+v.join(&#039;&#039;)&lt;br/&gt;}&lt;/p&gt;&lt;p&gt;window.onload = function(){&lt;/p&gt;&lt;p&gt;	var mystart = new Date().getTime();&lt;br/&gt;		for(var i=0;i&lt;1000;i++){&lt;/p&gt;&lt;p&gt;var e = rgbhex(&#039;rgb(204,255,109)&#039;);&lt;/p&gt;&lt;p&gt;		}&lt;br/&gt;	var myend = new Date().getTime();&lt;br/&gt;	&lt;br/&gt;	&lt;br/&gt;	var hisstart = new Date().getTime();&lt;br/&gt;		for(var i=0;i&lt;1000;i++){&lt;/p&gt;&lt;p&gt;var e = rgbToHexColor(&#039;rgb(204,255,109)&#039;);&lt;/p&gt;&lt;p&gt;		}&lt;br/&gt;	var hisend = new Date().getTime();&lt;br/&gt;	&lt;br/&gt;	&lt;br/&gt;alert( (myend - mystart) + &#039; :: &#039; + (hisend - hisstart) );&lt;br/&gt;	&lt;br/&gt;}&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi John, thanks for visiting the site and commenting.</p>
<p>Your code sample has some errors (odd single/double quote marks) that I needed to correct, but this could easily be attributed to your text editor or the formatting my blog chose to use.</p>
<p>I tested your code(fixed) versus my code in a loop that did the test loop 1000 times. In Firefox 3.0 and Safari 4 beta(the 2 browsers I tested in), my original code is generally faster than your sample. Additionally, the regex match does better validation about whether or not the string being passed in is an rgb value or not.</p>
<p>In Firefox 3.0.10 on Mac, running the test 10 times: <br />(My code :: Your code)<br />22 :: 26<br />21 :: 25<br />20 :: 27<br />21 :: 26<br />19 :: 25<br />20 :: 27<br />19 :: 25<br />21 :: 26<br />19 :: 27<br />22 :: 26</p>
<p>Safari 4(beta)<br />9 :: 7<br />8 :: 7<br />7 :: 6<br />8 :: 7<br />6 :: 7<br />8 :: 7<br />7 :: 7<br />8 :: 7<br />7 :: 8<br />7 :: 8</p>
<p>Safari has a very efficient js engine and for the most part, both of our versions are the same. But in the latest version of Firefox, my code is ~5 milliseconds faster. I would like to test this again in IE6/7/8 when I am able, but I suspect my version is faster there too. I would expect similar results as Safari for Chrome.</p>
<p>Here&#8217;s the code I used for the test:<br />//mine<br />rgbhex = function(rgbval){</p>
<p>	var s = rgbval.match(/rgb\s*\x28((?:25[0-5])|(?:2[0-4]\d)|(?:[01]?\d?\d))\s*,\s*((?:25[0-5])|(?:2[0-4]\d)|(?:[01]?\d?\d))\s*,\s*((?:25[0-5])|(?:2[0-4]\d)|(?:[01]?\d?\d))\s*\x29/);</p>
<p>	if(s){ s=s.splice(1); }<br />	if(s &#038;&#038; s.length==3){<br />		var d=&#8221;;<br />		for(i in s){<br />			var e=parseInt(s[i],10).toString(16);<br />			e == &#8220;0&#8243; ? d+=&#8221;00&#8243;:d+=e;<br />		} return &#8216;#&#8217;+d;<br />	}else{ return rgbval; }</p>
<p>}</p>
<p>//his<br />function rgbToHexColor(v) {<br />	v = v.split(&#8217;(')</p>
<p>	if(!v[1]) return v</p>
<p>	v = v[1].replace(/ /g, &#8221;).replace(/\)/, &#8221;)<br />	v = v.split(&#8217;,')</p>
<p>	for(i in v) {<br />		v[i] = Number(v[i]).toString(16)<br />		if(v[i].length==1) v[i] = &#8216;0&#8242; + v[i]<br />	}</p>
<p>	return &#8216;#&#8217;+v.join(&#8221;)<br />}</p>
<p>window.onload = function(){</p>
<p>	var mystart = new Date().getTime();<br />		for(var i=0;i&lt;1000;i++){</p>
<p>var e = rgbhex(&#8217;rgb(204,255,109)&#8217;);</p>
<p>		}<br />	var myend = new Date().getTime();</p>
<p>	var hisstart = new Date().getTime();<br />		for(var i=0;i&lt;1000;i++){</p>
<p>var e = rgbToHexColor(&#8217;rgb(204,255,109)&#8217;);</p>
<p>		}<br />	var hisend = new Date().getTime();</p>
<p>alert( (myend &#8211; mystart) + &#8216; :: &#8216; + (hisend &#8211; hisstart) );</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Middlemass</title>
		<link>http://trending.us/2009/01/07/javascript-rgb-to-hexadecimal-color-converter/#comment-21</link>
		<dc:creator>John Middlemass</dc:creator>
		<pubDate>Tue, 05 May 2009 15:30:39 +0000</pubDate>
		<guid isPermaLink="false">http://popped.at/?p=35#comment-21</guid>
		<description>&lt;p&gt;Quite similar but avoids the somewhat complex .match line&lt;/p&gt;&lt;p&gt;function rgbToHexColor(v) { &lt;br/&gt;v = v.split(&#039;(&#039;)&lt;br/&gt;if(!v[1]) return v&lt;br/&gt;v = v[1].replace(/ /g, &#039;&#039;).replace(/\)/, &#039;&#039;)&lt;br/&gt;v = v.split(&#039;,&#039;)&lt;br/&gt;for(i in v) {&lt;br/&gt;   v[i] = Number(v[i]).toString(16)&lt;br/&gt;   if(v[i].length==1) v[i] = &#039;0&#039; + v[i]&lt;br/&gt;}&lt;br/&gt;return &#039;#&#039;+v.join(&#039;&#039;)}&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Quite similar but avoids the somewhat complex .match line</p>
<p>function rgbToHexColor(v) { <br />v = v.split(&#8217;(')<br />if(!v[1]) return v<br />v = v[1].replace(/ /g, &#8221;).replace(/\)/, &#8221;)<br />v = v.split(&#8217;,')<br />for(i in v) {<br />   v[i] = Number(v[i]).toString(16)<br />   if(v[i].length==1) v[i] = &#8216;0&#8242; + v[i]<br />}<br />return &#8216;#&#8217;+v.join(&#8221;)}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Lawrence</title>
		<link>http://trending.us/2009/01/07/javascript-rgb-to-hexadecimal-color-converter/#comment-19</link>
		<dc:creator>Charles Lawrence</dc:creator>
		<pubDate>Fri, 13 Mar 2009 09:05:41 +0000</pubDate>
		<guid isPermaLink="false">http://popped.at/?p=35#comment-19</guid>
		<description>&lt;p&gt;Hi Uoon. Thanks for the feedback, but your function misses the point of what mine is trying to accomplish. Notice that I&#039;m not passing in the individual r/g/b values. I am simply passing in a string that matches the pattern rgb(255,255,255). As I say in the post, IE returns the CSS value, while other browsers return an rgb value. So by using my method, I don&#039;t have to worry about what the value is. &lt;/p&gt;&lt;p&gt;My use-case is that I will only be using the rgb converter method when appropriate, i.e. when I am trying to guarantee a detected color value is going to be returned as a hex code. So by using this when I need it, I will guarantee that I *always* get the hex code value.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Uoon. Thanks for the feedback, but your function misses the point of what mine is trying to accomplish. Notice that I&#8217;m not passing in the individual r/g/b values. I am simply passing in a string that matches the pattern rgb(255,255,255). As I say in the post, IE returns the CSS value, while other browsers return an rgb value. So by using my method, I don&#8217;t have to worry about what the value is. </p>
<p>My use-case is that I will only be using the rgb converter method when appropriate, i.e. when I am trying to guarantee a detected color value is going to be returned as a hex code. So by using this when I need it, I will guarantee that I *always* get the hex code value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: uoon</title>
		<link>http://trending.us/2009/01/07/javascript-rgb-to-hexadecimal-color-converter/#comment-17</link>
		<dc:creator>uoon</dc:creator>
		<pubDate>Fri, 13 Mar 2009 07:56:42 +0000</pubDate>
		<guid isPermaLink="false">http://popped.at/?p=35#comment-17</guid>
		<description>&lt;p&gt;function rgb(r, g, b) {&lt;br/&gt;  return &quot;#&quot; + (r + 256*g + 65536*b).toString(16);&lt;br/&gt;}&lt;/p&gt;&lt;p&gt;var text = &quot;rgb(20, 30, 40)&quot;;&lt;/p&gt;&lt;p&gt;var hex = eval(text);&lt;/p&gt;&lt;p&gt;alert(hex);&lt;/p&gt;&lt;p&gt;:)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>function rgb(r, g, b) {<br />  return &#8220;#&#8221; + (r + 256*g + 65536*b).toString(16);<br />}</p>
<p>var text = &#8220;rgb(20, 30, 40)&#8221;;</p>
<p>var hex = eval(text);</p>
<p>alert(hex);</p>
<p> <img src='http://trending.us/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: turmion</title>
		<link>http://trending.us/2009/01/07/javascript-rgb-to-hexadecimal-color-converter/#comment-18</link>
		<dc:creator>turmion</dc:creator>
		<pubDate>Mon, 02 Feb 2009 22:04:53 +0000</pubDate>
		<guid isPermaLink="false">http://popped.at/?p=35#comment-18</guid>
		<description>&lt;p&gt;hi! you&#039;re script had a bug...&lt;/p&gt;&lt;p&gt;function rgbToHex(rgbval){&lt;br/&gt;  var s = rgbval.match(/rgb\s*\x28((?:25[0-5])&#124;(?:2[0-4]\d)&#124;(?:[01]?\d?\d))\s*,\s*((?:25[0-5])&#124;(?:2[0-4]\d)&#124;(?:[01]?\d?\d))\s*,\s*((?:25[0-5])&#124;(?:2[0-4]\d)&#124;(?:[01]?\d?\d))\s*\x29/);&lt;br/&gt;  if(s){ &lt;br/&gt;    s=s.splice(1); &lt;br/&gt;    if(s &amp;&amp; s.length==3){&lt;br/&gt;        d=&#039;&#039;;&lt;br/&gt;        for(i in s){&lt;br/&gt;            e=parseInt(s[i],10).toString(16);&lt;br/&gt;            if(e.length == 1){&lt;br/&gt;              e == &quot;0&quot; ? d+=&quot;00&quot; : d+= (&quot;0&quot; + e);&lt;br/&gt;            }else{&lt;br/&gt;              d+=e;&lt;br/&gt;            }&lt;br/&gt;        } return &#039;#&#039;+d;&lt;br/&gt;    }else{ &lt;br/&gt;      return rgbval;&lt;br/&gt;    }&lt;br/&gt;  }else{&lt;br/&gt;    return rgbval;&lt;br/&gt;  }&lt;br/&gt;}&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>hi! you&#8217;re script had a bug&#8230;</p>
<p>function rgbToHex(rgbval){<br />  var s = rgbval.match(/rgb\s*\x28((?:25[0-5])|(?:2[0-4]\d)|(?:[01]?\d?\d))\s*,\s*((?:25[0-5])|(?:2[0-4]\d)|(?:[01]?\d?\d))\s*,\s*((?:25[0-5])|(?:2[0-4]\d)|(?:[01]?\d?\d))\s*\x29/);<br />  if(s){ <br />    s=s.splice(1); <br />    if(s &amp;&amp; s.length==3){<br />        d=&#8221;;<br />        for(i in s){<br />            e=parseInt(s[i],10).toString(16);<br />            if(e.length == 1){<br />              e == &#8220;0&#8243; ? d+=&#8221;00&#8243; : d+= (&#8221;0&#8243; + e);<br />            }else{<br />              d+=e;<br />            }<br />        } return &#8216;#&#8217;+d;<br />    }else{ <br />      return rgbval;<br />    }<br />  }else{<br />    return rgbval;<br />  }<br />}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

