Colors integers, Hexs and ARGBs

Cableguy

Expert
Licensed User
Longtime User
I've spent most of my afternoon googling, and testing lots of color converters...

I just cant understand how B4A, or android, represents/calculates the colors integers.

Let's take the example of the color named "aliceblue", wich has an HEX representation of FF F0 F8 FF and in ARGB 255,240,248,255.
A "simple" Hex to Dec convertion gives me 4293982463, but this does not give me the color I intended to on screen...
So, if I have the Hex and/or ARGB notation, what is the formula to calculate the color's integer?
 

barx

Well-Known Member
Licensed User
Longtime User
Think you have gone wrong somewhere.

Hex Dec
FF 255
F0 240
F8 248
FF 255

what figure were your hex-dec 'ing
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I copied the Hex value to excel, and used the HexDec Formula wich takes only one argument,wich is the Hex value...

But as I say, I've been trying a series of online hex/rgb converters, and never getting the corespondent color on screen...

Using my test sample app, passing the ARGB values to the file gives me the integer -984833 (why the minus?)
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
-984833 is the correct signed integer representation for your colour. Colours are represented as signed integers. 4293982463 is the unsigned integer representation of your number and is out of the range of permissible values for a signed integer so when it gets assigned to a signed integer the resulting value is not what you expect.

Also note that Basic4android can accept hex literals formated as 0xfff08fff.

B4X:
Activity.Color = 0xfff0f8ff
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
SO my conversion was NOT wrong...hehehe

I took the time while waiting and came up with a small (!) converter, wich took a hardcoded list of color names and their RGB values and converted to the "signed" notation that B4A uses.
Then I copied the vaues to the "original" table, and here you are.
 

Attachments

  • tabela de cores.zip
    17.3 KB · Views: 729
  • Colors.zip
    6.9 KB · Views: 824
Upvote 0

pauleffect

Member
Licensed User
Longtime User
-984833 is the correct signed integer representation for your colour. Colours are represented as signed integers. 4293982463 is the unsigned integer representation of your number and is out of the range of permissible values for a signed integer so when it gets assigned to a signed integer the resulting value is not what you expect.

Also note that Basic4android can accept hex literals formated as 0xfff08fff.

B4X:
Activity.Color = 0xfff0f8ff

Dude.... there's no freaking way I can thank you enough for this!
 
Upvote 0
Top