Android (AI2) Colour Number Finder App

Skip to first unread message

Tim Carter

Mar 3, 2017, 8:10:32 PM3/3/17
to MIT App Inventor Forum
Way back in 2011, a developer asked to be able to get a colour number value from RGBA codes.

Someone somewhere had done the calculations which I put together on a google sheet. @ 45 developers have since accessed the sheet.

Maybe you didn't know that you can use a number instead of the colour blocks to set the colour of a component in AI2?

The above will produce Black.

Finally got around to creating an app to do the same thing!

It is in the Gallery as Android Colour Number Finder

Hopefully has a use in some situations ;)

Boban Stojmenovic

Mar 4, 2017, 5:51:10 PM3/4/17
to MIT App Inventor Forum

as well as you have two numbers that you can use here is a simpler code to do this without calculating 

Tim Carter

Mar 5, 2017, 5:49:53 AM3/5/17
to MIT App Inventor Forum
@ Boban

You are right! No obvious logic there:

make color = 4278190080 = -16777216

but it works. I guess the make color block is feeding the minus value to the background, whilst displaying the result

Evan Patton

Mar 5, 2017, 8:30:09 AM3/5/17
to MIT App Inventor Forum
@Tim Carter

Here is the logic:

T he value of the color in hex is FF000000 (255 alpha, 0 rgb). This value in decimal is 4278190080. In YAIL, the values are stored as long (64-bit) or Java Bignums (if they're larger than 2^63), which can represent this large positive value. However, when the value is passed to the Android runtime, it is passed as a Java int, which is a signed 32-bit value. When FF000000 is interpreted as a 32-bit signed integer, it's value is -16777216.

So at the bit representation they are equivalent, it's all in how the bits are interpreted.


Tim Carter

Mar 5, 2017, 9:20:51 AM3/5/17
to MIT App Inventor Forum
Thanks Evan ;)

Juan Antonio

Mar 5, 2017, 9:47:48 AM3/5/17
to MIT App Inventor Forum
Reply all
Reply to author
0 new messages