Re: Fast computation of parity

From: ScottD (bubba_at_aol.com)
Date: 12/31/03


Date: Wed, 31 Dec 2003 07:42:58 -0600


"Mok-Kong Shen" <mok-kong.shen@t-online.de> wrote in message
news:3FF1C6BD.81239059@t-online.de...
>
>
> ScottD wrote:
> >
>
> > Here is a non-portable solution for x86:
> >
> > int parity (long int value)
> > {
> > __asm mov eax, value
> > __asm or eax, eax
> > __asm setp al
> > __asm and eax,1
> > }
>
> I attempted to use the above. However, the compiler
> complained that there is no return value. Could you fix
> that (since I know too little about asm)? (BTW, after
> an operation, the parity of the least significant
> byte is given in a parity flag, as far as I know.
> Could one make use of that, or have you already used
> that in the above?) Thanks.
>
> M. K. Shen

You are correct about the parity operation applying to the
least significant byte only. This code is completely incorrect
for that reason. Thanks for point that out. I tested the code,
but only with a few values that happened to fit in a single byte.

-- 
Scott


Relevant Pages

  • Re: Fast computation of parity
    ... > ScottD wrote: ... However, the compiler ... Could you fix ... mistake and assumed the parity flag applied to all 32 bits. ...
    (sci.crypt)
  • Re: Fast computation of parity
    ... > ScottD wrote: ... However, the compiler ... Could you fix ... mistake and assumed the parity flag applied to all 32 bits. ...
    (sci.crypt)
  • Re: Fast computation of parity
    ... > int parity ... However, the compiler ... Could you fix ... the parity of the least significant ...
    (sci.crypt)
  • Re: 1956 IBM hard drive
    ... Somebody needs to fix the Wiki. ... It was 7 bits (remember the "odd parity"?) ... In the 8 bit ASCII code the 8th bit is the parity bit. ...
    (rec.boats)