[Ffmpeg-devel] H.264 encoder

Morten Nilsen morten
Wed Oct 4 19:00:41 CEST 2006


Christian Iversen wrote:
>>>> +                if (val > 0)
>>>> +                    val--;
>>>> +                else // < 0
>>>> +                    val++;
>>> val -= (val>>31)|1;
> 
> Is it because I appearantly don't understand C, or is that a pretty odd 
> expression? 
> 
> You take the sign bit, and "or" it with 1, leaving ... 1, in all cases.
> 
> Is this expression equiv. to val--; ? 


-xxx >> 31 = -1
 xxx >> 31 =  0

-1 | 1 = -1
 0 | 1 =  1

so, we get;
negative: val -= -1;
positive: val -=  1;

Quite elegant, I just love bit magic. :)

-- 
Morten
:wq




More information about the ffmpeg-devel mailing list