Maths / bitwise question

I have a file where colors were stored as  decimal integers

To get the r, g, b    I divide the integer by 1, 256, or 65536   then take the low byte by bitwise and-ing with &hFF

         r = bitwiseand( thecol , 255)

         g = bitwiseand(thecol / 256,255)

         b = bitwiseand(thecol/65536,255)

Is there an equivalent in Lua?

eg    from a decimal value that is   &h13F     be able to get the decimal equivalent of the 3F  part?

You can use the free Bit plugin to do this:

https://docs.coronalabs.com/plugin/bit/index.html

…fwiw, not that there’s anything wrong with the bit plugin, but for pow-of-2 masks modulo can substitute, fe:

r = math.floor(rgb/65536) – assumes uppermost alpha byte is zero, else apply modulo here also

g = math.floor(rgb/256) % 256

b = rgb % 256

 

Check out this you may get idea.

http://developer.android.com/reference/android/graphics/Color.html

You can use the free Bit plugin to do this:

https://docs.coronalabs.com/plugin/bit/index.html

…fwiw, not that there’s anything wrong with the bit plugin, but for pow-of-2 masks modulo can substitute, fe:

r = math.floor(rgb/65536) – assumes uppermost alpha byte is zero, else apply modulo here also

g = math.floor(rgb/256) % 256

b = rgb % 256

 

Check out this you may get idea.

http://developer.android.com/reference/android/graphics/Color.html