Huh !?

Something I never really gave much thought about made me do a bit of a double take today.

If you assign a color literal to a color variable you get what might look like “funny” behaviour when compared to other types of variables.

For instance, if you do

Dim c As Color = &c12345

what you get in the color is the color value &c12345000, a right zero fill, instead of &c00012345, a left zero fill.

If however you do something like

Dim i32 As Int32 = &h12345

what you get is a 32 bit value that is analogous to &h00012345 and its left zero filled.

So why does a color do a zero fill on the “right” and yet an integer, which is also a 32 bit value, you get what looks like a zero fill on the left ?

I suppose internally the compiler is actually doing something like

Dim i32 As Int32 = Int32 (&h12345)
Dim c As Color = Color(i32)

It first converts the &c notation into an Int32 which is then recast as a color and since a color, in hex, is actually AARRGGBB where a color is RRGGBBAA this is why you get the apparent “right zero fill” for a color.

One of those things you just take for granted and never really think about.

Now what got me even thinking about this ? The code editors display of a color literal.

It struck me that IF a color literal was left zero filled like you might assume it would be then this image SHOULD look like this

But, since I assume the compiler is doing the conversion of a color via an Int32. you get LEFT zero filling on the color constant and it shows up the way it does.

One of those things I just never really thought of in all the time I’ve used Xojo.