parity(Number) -> parity(Number, 0).
parity(Number, Count) when Number band 1 == 1 ->
parity(Number bsr 1, Count + 1);
parity(Number, Count) when Number > 0 ->
parity(Number bsr 1, Count);
parity(_, Count) ->
Count rem 2.
print *,poppar(i)
let i = 42
i.toString(2)
.split('')
.reduce((parity, bit) => parity ^ bit, 0)
function Parity(n: Integer): Integer;
var
Mask, I, Bits: Integer;
begin
Bits := 0;
for I := 0 to SizeOf(Integer)*8 - 1 do
begin
Mask := 1 shl I;
if ((n and Mask) <> 0) then Inc(Bits);
end;
Result := Ord(Odd(Bits));
end;
begin
writeln(Parity(42));
end.
function Parity(n: Int32): Integer;
begin
Result := Ord(Odd(PopCnt(DWORD(n))));
end;
var
i: Int32;
begin
i := 42;
writeln('Parity(42) = ',Parity(i));
end.
function Parity(n: Integer): Integer;
var
Mask, I, Bits: Integer;
begin
Bits := 0;
for I := 0 to SizeOf(Integer)*8 - 1 do
begin
Mask := 1 shl I;
if ((n and Mask) <> 0) then Inc(Bits);
end;
Result := Ord(Odd(Bits));
end;
begin
writeln(Parity(42));
end.
function Parity(n: Int32): Integer;
begin
Result := Ord(Odd(PopCnt(DWORD(n))));
end;
var
i: Int32;
begin
i := 42;
writeln('Parity(42) = ',Parity(i));
end.