Bitwise-or operator used on a sign-extended operand

  • Thread starter Thread starter Dylan Parry
  • Start date Start date
D

Dylan Parry

Hi folks,

I've been getting the following warning when compiling my code,
"Bitwise-or operator used on a sign-extended operand; consider casting
to a smaller unsigned type first", and although it doesn't have any
detrimental effect, I would love to be able to get rid of it.

The code that it refers to is:

public static int RGB(byte r, byte g, byte b) {
return (int) (((byte) (r) | ((ushort) (g) << 8)) | (((uint) (byte)
(b)) << 16));
}

Which is something I didn't write myself, so I don't actually understand
what it's doing, otherwise I might have fixed it by now!

Any ideas how to stop the warning occurring without altering the
returned value?
 
I *think* the following is equiv:

return ((int) r) | (((int) g) << 8) | (((int) b) << 16);

Marc
 
Marc said:
I *think* the following is equiv:

return ((int) r) | (((int) g) << 8) | (((int) b) << 16);

Cheers. It does appear to generate colours in my application that look
identical at least, so that's good enough for me!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top