puzzlecracker wrote:[color=blue]
> what does it do?
> #define BLACKBOX(x) ((x)&((x)-1))[/color]
For unsigned integers x and signed integers x in 2s complement
with x>(integer type's minimum value), this clears the least
significant set bit.
It also works for 1s complement signed integers and
x!=0 && x!=1 && x>(integer type's minimum value)
-Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Luke Wu wrote:[color=blue]
> puzzlecracker wrote:
>[color=green]
>>what does it do?
>>#define BLACKBOX(x) ((x)&((x)-1))[/color]
>
>
> Clears the least significant set bit in x. This works on all unsigned
> numbers and all signed numbers (except "sign-magnitude" negative even
> numbers).[/color]
.... and except for x==T_MIN where T is the respective integer type;
in the case of 1s complement you cannot rely on 0 not switching
its representation, so x==0 and x==1 are not guaranteed to work
either.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
> puzzlecracker wrote:[color=blue][color=green]
> > what does it do?
> > #define BLACKBOX(x) ((x)&((x)-1))[/color][/color]
What do you think it does?
If you want to 'test' clc, at least try to be original.
Michael Mair wrote:[color=blue]
>
> For unsigned integers x and signed integers x in 2s complement
> with x>(integer type's minimum value), this clears the least
> significant set bit.
> It also works for 1s complement signed integers and
> x!=0 && x!=1 && x>(integer type's minimum value)[/color]
No, consider the following (high bit is sign-bit):
1c or 2c(C99) sm
x : 10000000 10000000 10000000 01111111
x - 1: 10000000 01111111 10000000 10000000
& : 10000000 00000000 10000000 00000000
The result could be a trap representation.
Note also that C89 potentially allows negative representations
beyond 2c, 1c and sm.
On 21 Feb 2005 13:08:16 -0800, "Luke Wu" <LookSkywalker@ gmail.com> wrote:
[color=blue]
>
>puzzlecracke r wrote:[color=green]
>> what does it do?
>> #define BLACKBOX(x) ((x)&((x)-1))[/color]
>
>Clears the least significant set bit in x. This works on all unsigned
>numbers and all signed numbers (except "sign-magnitude" negative even
>numbers).[/color]
Inputting the integer '8' causes the "function" to return zero. Not
suprizing, since the original poster is a known troll.
bk039@ncf.ca (Raymond Martineau) writes:
[color=blue]
> On 21 Feb 2005 13:08:16 -0800, "Luke Wu" <LookSkywalker@ gmail.com> wrote:[color=green]
>>puzzlecrack er wrote:[color=darkred]
>>> what does it do?
>>> #define BLACKBOX(x) ((x)&((x)-1))[/color]
>>
>>Clears the least significant set bit in x. This works on all unsigned
>>numbers and all signed numbers (except "sign-magnitude" negative even
>>numbers).[/color]
>
> Inputting the integer '8' causes the "function" to return zero. Not
> suprizing, since the original poster is a known troll.[/color]
8 has only one bit set. Clearing that bit, which is necessarily
the least significant set bit, yields 0. Thus, this is correct
behavior.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Raymond Martineau wrote:[color=blue]
> On 21 Feb 2005 13:08:16 -0800, "Luke Wu" <LookSkywalker@ gmail.com>[/color]
wrote:[color=blue]
>[color=green]
> >
> >puzzlecracke r wrote:[color=darkred]
> >> what does it do?
> >> #define BLACKBOX(x) ((x)&((x)-1))[/color]
> >
> >Clears the least significant set bit in x. This works on all[/color][/color]
unsigned[color=blue][color=green]
> >numbers and all signed numbers (except "sign-magnitude" negative[/color][/color]
even[color=blue][color=green]
> >numbers).[/color]
>
> Inputting the integer '8' causes the "function" to return zero.[/color]
Yes, exactly as Luke said. What's your point?
[color=blue]
> Not suprizing, since the original poster is a known troll.[/color]
Peter Nilsson wrote:[color=blue][color=green]
>>puzzlecrack er wrote:
>>[color=darkred]
>>>what does it do?
>>>#define BLACKBOX(x) ((x)&((x)-1))[/color][/color]
>
>
> What do you think it does?
>
> If you want to 'test' clc, at least try to be original.[/color]
Ack.
[color=blue]
> Michael Mair wrote:
>[color=green]
>>For unsigned integers x and signed integers x in 2s complement
>>with x>(integer type's minimum value), this clears the least
>>significant set bit.
>>It also works for 1s complement signed integers and
>> x!=0 && x!=1 && x>(integer type's minimum value)[/color]
>
> No, consider the following (high bit is sign-bit):
>
> 1c or 2c(C99) sm
> x : 10000000 10000000 10000000 01111111
> x - 1: 10000000 01111111 10000000 10000000
> & : 10000000 00000000 10000000 00000000
>
> The result could be a trap representation.[/color]
Just to make sure: Your "no" is referring to the fact that we
could get a trap representation? Or do you mean that the
formulation "least significant bit" is incorrect?
I am not sure what you want to say with the sign-magnitude example
-- most certainly the "lowest" bit of x is not cleared.
[color=blue]
> Note also that C89 potentially allows negative representations
> beyond 2c, 1c and sm.[/color]
Thank you for the reminder (mostly, I assume C99 _restrictions_
for everything and am surprised if C89 is not as strict).
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.
Comment