# www.jpct.net

## jPCT - a 3d engine for Java => Support => Topic started by: AGP on December 28, 2020, 09:08:48 pm

Title: Programming Question (Bitwise OR)
Post by: AGP on December 28, 2020, 09:08:48 pm
Does it make any difference to bitwise OR 4278190080u and -16777216 (for alpha values) if the result will nevertheless be an unsigned int (I apologize in advance for the C#)?
Title: Re: Programming Question (Bitwise OR)
Post by: EgonOlsen on December 29, 2020, 04:29:24 pm
Depends on the implementation, I guess. Just write a simple test case and try it. In case of doubt, I would go with a bitwise or hex representation of the number instead like 0b11111111111.... or 0xfffffff... if that's supported by C#.
Title: Re: Programming Question (Bitwise OR)
Post by: AGP on December 29, 2020, 09:31:54 pm
Tell me if you think that the numbers matching here is sufficient proof that it's the same thing (the ifs are there just in case):
Code: [Select]
` int ALPHA = 255 << 24; uint r = 1, g = 1, b = 2; if ((r & 0xffffff00) != 0) { r = (255u >> (int)(r >> 28 & 8)); } if ((g & 0xffffff00) != 0) { g = (255u >> (int)(g >> 28 & 8)); } if ((b & 0xffffff00) != 0) { b = (255u >> (int)(b >> 28 & 8)); } uint fromSigned = (uint)(b | (g << 8) | (r << 16) | ALPHA); uint fromUnsigned = b | (g << 8) | (r << 16) |4278190080u; System.Console.WriteLine("OR from Signed: "+fromSigned +", from Unsigned: "+fromUnsigned);`
Title: Re: Programming Question (Bitwise OR)
Post by: EgonOlsen on December 30, 2020, 11:00:18 am
If these are giving the same results, it should be fine.