Hexadecimal Woes

  • Thread starter Thread starter Bryan Loeper
  • Start date Start date
B

Bryan Loeper

I'm working with coloring some reports and have been trying to define
colors (via enum) for them.

1) Why is it that RGB(a,b,c) ends up being in BGR order as HEX?
Example:
&H996633 = 10053171
RGB(153,102,51) = 3368601
RGB(51,102,153) = 10053171

2) Why is it that &HCCFF appears to be (what I think is) the two's
compliment to 0xCCFF?
&HCCFF = -13057
-13057 = -0x3301
0x3301 + 0xCCFF = 0x10000

I've got the color issues for my program figured out, I'm just curious
about why Excel behaves this way. I did a quick Google search that
didn't bring up any complaints about this, so I figure I must not be
understanding How Things Work correctly. Thanks for any insight you
can offer!

-Bryan
 
While a good resource for color, that page doesn't really answer
either of my questions.
 
1. Each RGB value occupies a byte (0-255). In VB/A RGB values are placed in
order least to most significant byte:-

&Hbbggrr

In many languages, perhaps the majority, the byte order is reversed.
Strangely, some API's use RGB and others BRG.

2. I don't really understand what the question is, and why you are only
dealing with two of the three RGB bytes.
But, whatever it is, perhaps your confusion might relate to your mixing
Integer Hex (2 byte) and Long Hex (4 byte) values

&HCCFF = -13057

values 0 to &H7FFF are +ve, 0 to 32767
values &H8000 to &HFFFF are -ve, -32768 to -1

to coerce to a Long add the &
&HCCFF& = 52479 = rgb(255,204,000)

Regards,
Peter T
 
Ok, I think I understand number 1 as far as theory goes. As for
number 2, whenever I put in &H00CCFF, it always gets shortened to
&HCCFF. Thanks for the clarification about the second '&'! It was
exactly what I was looking for.

-Bryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top