• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hex Conversion  RSS feed

 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an idea.

I want to store color information in a short instead of an int.

Currently color information is stored in an int like so:

0x00RRGGBB

I want to use this format:

0x0RGB

Is there a formula or bit shift I can use to do the conversion back and forth?

I realize I will have less colors to work with using a short, but there should be plenty for what I need.

Thanks,

Drew
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just as a guess I would think you will mask off each section and do a division based on the difference.

int redmask = 0x00FF0000;

int red = color & redmask;
red = red >> 16;
red = red/16;

I didn't check any of this, but I think that would roughly downgrade the image to the lower color depth. You would do that for each color Then you would have to bit shift them back and | them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!