[IPOL discuss] RGB->gray conversion and speed comparison

Miguel Colom Miguel.Colom at cmla.ens-cachan.fr
Fri Jul 29 18:31:51 CEST 2011


>> I think the problem could arise in this bit-wise AND:
>> "& (1 << 14)"
>>
>> Not all architectures will store the 14th bit in the same position
>> inside
>> a integer.
>
> The meaning of >> and << is not related to the memory representation
> of the numbers.

My doubt was about the use of the "&" operator, not the shifts.

Nowadays most modern machines use 2's complement to represent integer
numbers, so 16384 will contain only one bit equal to one a the other set
to zero.

The use of the "&" operator assumes this situation and relies on the fact
than only one bit will be set when representing number 16384.

Almost all modern machines use 2's complement to represent numbers, so
this assumption is true for them, but this doesn't mean that this isn't a
architecture-dependent computation.

I agree the shift operators << and >> are architecture-independent, but
"&" isn't.



More information about the discuss mailing list