xmame  

Re: Insignificant unofficial b10 bug

Gabriele Boccone
Tue, 12 Dec 2000 12:22:12 -0800

Pete French wrote:

> > What about that: (-1)^(-1>>1) ?
>
> the casts break it - the cosntant "-1" has the type of 'signed int' so
> when you do a >> on it the sign bit is preserved.
>
>         int a;
>         a = -1;
>         printf("a in hex is %x\n",a);
>         a = a >> 1;
>         printf("a in hex is %x\n",a);
>
> produces the output:
>
> a in hex is ffffffff
> a in hex is ffffffff
>
> which is not what you expect!

Ok. That's right. But I seem to remember I actually did it... maybe by casting
((unsigned int)(-1)>>1) you get it right? I'll try that... just wait a few
lines...

Here it is:

        unsigned int a;
        a = -1;
        printf("a in hex is %x\n",a);
        a = a >> 1;
        printf("a in hex is %x\n",a);

now try this, you get the "right" output:

a in hex is ffffffff
a in hex is 7fffffff



---------------------------------------------------------------------------
Send administrative requests to [EMAIL PROTECTED]