<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title/>
    <description>Snipplr comments feed</description>
    <link>https://ipv6.snipplr.com/</link>
    <lastBuildDate>Mon, 06 Apr 2026 05:35:38 +0000</lastBuildDate>
    <item>
      <title>PeteW said on 20/Jul/2010</title>
      <link>https://ipv6.snipplr.com/view/4621/convert-hex-to-rgb--rgb-to-hex</link>
      <description>&lt;p&gt;I'm afraid there's a bug in RGBToHex.&#13;
&#13;
You need to pad each hex value, otherwise your full hex number could end up being 3, 4 or 5 digits.&#13;
&#13;
For instance, the following would both generate #22222, despite being different colours:&#13;
RGBToHex (2, 34, 34);&#13;
RGBToHex (34, 34, 2);&#13;
&#13;
Try this:&#13;
&#13;
function RGBToHex($r, $g, $b) {&#13;
		$hex = "#";&#13;
		$hex.= str_pad(dechex($r), 2, '0', STR_PAD_LEFT );&#13;
		$hex.= str_pad(dechex($g), 2, '0', STR_PAD_LEFT );&#13;
		$hex.= str_pad(dechex($b), 2, '0', STR_PAD_LEFT );&#13;
 &#13;
		return $hex;&#13;
	}&lt;/p&gt;</description>
      <pubDate>Tue, 20 Jul 2010 19:27:53 UTC</pubDate>
      <guid>https://ipv6.snipplr.com/view/4621/convert-hex-to-rgb--rgb-to-hex</guid>
    </item>
    <item>
      <title>PeteW said on 20/Jul/2010</title>
      <link>https://ipv6.snipplr.com/view/4621/convert-hex-to-rgb--rgb-to-hex</link>
      <description>&lt;p&gt;I'm afraid there's a bug in RGBToHex.&#13;
&#13;
You need to pad each hex value, otherwise your full hex number could end up being 3, 4 or 5 digits.&#13;
&#13;
For instance, the following would both generate #22222, despite being different colours:&#13;
RGBToHex (2, 34, 34);&#13;
RGBToHex (34, 34, 2);&#13;
&#13;
Try this:&#13;
&lt;code&gt;&#13;
function RGBToHex($r, $g, $b) {&#13;
		$hex = "#";&#13;
		$hex.= str_pad(dechex($r), 2, '0', STR_PAD_LEFT );&#13;
		$hex.= str_pad(dechex($g), 2, '0', STR_PAD_LEFT );&#13;
		$hex.= str_pad(dechex($b), 2, '0', STR_PAD_LEFT );&#13;
 &#13;
		return $hex;&#13;
	}&#13;
&lt;/code&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 20 Jul 2010 19:28:35 UTC</pubDate>
      <guid>https://ipv6.snipplr.com/view/4621/convert-hex-to-rgb--rgb-to-hex</guid>
    </item>
    <item>
      <title>PeteW said on 20/Jul/2010</title>
      <link>https://ipv6.snipplr.com/view/4621/convert-hex-to-rgb--rgb-to-hex</link>
      <description>&lt;p&gt;Meh, Snipplr doesn't seem to want to display my code properly, but hopefully you get the idea.&lt;/p&gt;</description>
      <pubDate>Tue, 20 Jul 2010 19:29:30 UTC</pubDate>
      <guid>https://ipv6.snipplr.com/view/4621/convert-hex-to-rgb--rgb-to-hex</guid>
    </item>
    <item>
      <title>Cory said on 16/Oct/2010</title>
      <link>https://ipv6.snipplr.com/view/4621/convert-hex-to-rgb--rgb-to-hex</link>
      <description>&lt;p&gt;Cool thanks for that info on the bug I fixed the issue.&lt;/p&gt;</description>
      <pubDate>Sat, 16 Oct 2010 11:16:21 UTC</pubDate>
      <guid>https://ipv6.snipplr.com/view/4621/convert-hex-to-rgb--rgb-to-hex</guid>
    </item>
    <item>
      <title>indeed said on 03/Dec/2011</title>
      <link>https://ipv6.snipplr.com/view/4621/convert-hex-to-rgb--rgb-to-hex</link>
      <description>&lt;p&gt;Thank you!&lt;/p&gt;</description>
      <pubDate>Sat, 03 Dec 2011 07:34:41 UTC</pubDate>
      <guid>https://ipv6.snipplr.com/view/4621/convert-hex-to-rgb--rgb-to-hex</guid>
    </item>
  </channel>
</rss>
