# Algorithm newsgroup?

Discussion in 'C Programming' started by Paminu, Oct 5, 2005.

1. ### PaminuGuest

Where do I find an algorithm newsgroup?

I am interested in getting some help with the "even parity check" algorithm.
I used google to find this back in 1999 from this newsgroup:

unsigned parity(unsigned arg)
{
unsigned a = arg;

a ^= a >> 16;
a ^= a >> 8;
a ^= a >> 4;
a ^= a >> 2;
a ^= a >> 1;

return a & 1;
}

Who have invented this algorithm?

Is it possible to find an explanation somewhere because I see that it works
but would never myself have come up with it and would very much like to
know the theory behind it.

Paminu, Oct 5, 2005

2. ### Alexei A. FrounzeGuest

"Paminu" <> wrote in message
news:dhvurc\$pv3\$-c.dk...
> Where do I find an algorithm newsgroup?

I can only suggest a Russian one, fido7.ru.algorithms which would work for
you only through a FIDO gateway and anyway most people there are Russian
speaking, so, I'm not sure you'll find it suitable for you...

> I am interested in getting some help with the "even parity check"

algorithm.
> I used google to find this back in 1999 from this newsgroup:
>
> unsigned parity(unsigned arg)
> {
> unsigned a = arg;
>
> a ^= a >> 16;
> a ^= a >> 8;
> a ^= a >> 4;
> a ^= a >> 2;
> a ^= a >> 1;
>
> return a & 1;
> }
>
> Who have invented this algorithm?

I have. Some Mr. John Brown has. Many people have invented that on their own
independently.

> Is it possible to find an explanation somewhere because I see that it

works
> but would never myself have come up with it and would very much like to
> know the theory behind it.

The explanation is simple: you XOR all bits of the number to get a single
bit in the end. The above does it very well, and w/o an unnecessary loop, I
must say.
But this is all Off Topic in this group as you may know... So, I'm shutting
up right here (had to do that in the beginning though).

Alex

Alexei A. Frounze, Oct 5, 2005

3. ### PaminuGuest

Alexei A. Frounze wrote:

> "Paminu" <> wrote in message
> news:dhvurc\$pv3\$-c.dk...
>> Where do I find an algorithm newsgroup?

>
> I can only suggest a Russian one, fido7.ru.algorithms which would work for
> you only through a FIDO gateway and anyway most people there are Russian
> speaking, so, I'm not sure you'll find it suitable for you...
>
>> I am interested in getting some help with the "even parity check"

> algorithm.
>> I used google to find this back in 1999 from this newsgroup:
>>
>> unsigned parity(unsigned arg)
>> {
>> unsigned a = arg;
>>
>> a ^= a >> 16;
>> a ^= a >> 8;
>> a ^= a >> 4;
>> a ^= a >> 2;
>> a ^= a >> 1;
>>
>> return a & 1;
>> }
>>
>> Who have invented this algorithm?

>
> I have. Some Mr. John Brown has. Many people have invented that on their
> own independently.
>
>> Is it possible to find an explanation somewhere because I see that it

> works
>> but would never myself have come up with it and would very much like to
>> know the theory behind it.

>
> The explanation is simple: you XOR all bits of the number to get a single
> bit in the end. The above does it very well, and w/o an unnecessary loop,
> I must say.
> But this is all Off Topic in this group as you may know... So, I'm
> shutting up right here (had to do that in the beginning though).
>
> Alex

hmm but since there is only russian newsgroups covering algorithms would
this group not be the most obvious group to discuss these kind of issues?

If not is there any other alternatives?

Paminu, Oct 5, 2005
4. ### peteGuest

Paminu wrote:

> unsigned a = arg;
>
> a ^= a >> 16;

That's undefined if UCHAR_MAX equals 0xffffu.

--
pete

pete, Oct 5, 2005
5. ### peteGuest

Paminu wrote:
>
> Alexei A. Frounze wrote:
>
> > "Paminu" <> wrote in message
> > news:dhvurc\$pv3\$-c.dk...
> >> Where do I find an algorithm newsgroup?

news:comp.programming

--
pete

pete, Oct 5, 2005
6. ### SkarmanderGuest

pete wrote:
> Paminu wrote:
>
>
>> unsigned a = arg;
>>
>> a ^= a >> 16;

>
>
> That's undefined if UCHAR_MAX equals 0xffffu.
>

UINT_MAX, of course.

And although you're right, we presumably aren't supposed to care.
Otherwise a loop *would* be more appropriate, to accommodate unsigned
ints of arbitrary sizes.

S.

Skarmander, Oct 5, 2005
7. ### Alexei A. FrounzeGuest

"Paminu" <> wrote in message
news:di004u\$q85\$-c.dk...
> hmm but since there is only russian newsgroups covering algorithms would
> this group not be the most obvious group to discuss these kind of issues?
>
> If not is there any other alternatives?

I simply don't know others. I prefer first to get my own solution, then look
for any hint elsewhere if I don't like mine (e.g. too complicated, too slow)
or if it's just incorrect/incomplete (e.g. doesn't cover the cases which I
don't know at all or don't understand clearly). As for understanding why
something works the way it does, if you have the code/formula for it, you
generally can understand that, not always quickly, however, especially if
either the formal language or the problem at hand (or both) isn't familiar
to you. It all depends on the experience, level of ignorance, logical
reasoning and researching skills, laziness and attitude, or, in other words,
on your past, present and where you want to get with all that in the future.

Alex

Alexei A. Frounze, Oct 5, 2005
8. ### peteGuest

Skarmander wrote:
>
> pete wrote:
> > Paminu wrote:
> >
> >
> >> unsigned a = arg;
> >>
> >> a ^= a >> 16;

> >
> >
> > That's undefined if UCHAR_MAX equals 0xffffu.
> >

> UINT_MAX, of course.

Yes.

--
pete

pete, Oct 5, 2005