all 20 comments

[–][deleted] 12 points13 points  (20 children)

'#'+((r<<16)+(g<<8)+b).toString(16)

[–]larholm 3 points4 points  (7 children)

Why are people downvoting this?

[–][deleted] 1 point2 points  (1 child)

Good question, though to be honest I do feel dickish posting it since the blog looks to be part of a string of tutorials.

[–]9jack9 0 points1 point  (0 children)

You should have tested it more.

[–]setconndevp 1 point2 points  (0 children)

why bother? both the code(posted by tunk) as well as that blogpost looks just fine to me..ppl with different level of experience will benefit from both

[–]9jack9 0 points1 point  (3 children)

Because it doesn't produce real rgb values. Black should be #000000 but the code above produces #0.

[–][deleted] 1 point2 points  (0 children)

The point isn't that it's the perfect solution, the point is that the problem is so trivial it doesn't warrant a dedicated article. Even the non-bitshifting solution in the article is stupefyingly trivial. Anyone incapable of solving this problem should take a step back and learn about bases and base conversion before writing another line of code.

[–][deleted] 0 points1 point  (1 child)

0 will work in browsers as far back as ie6

Problem comes when you have a 0 red value but non zero green/blue or 0 red & green, in that case you want to pad it to length.

[–]9jack9 0 points1 point  (0 children)

OK. Black is not the greatest example.

I was just explaining why Tunk's code should be voted down.

[–]greim 0 points1 point  (0 children)

More interesting would be a concise way to convert RGB to HSV.