FORTRAN POPPAR Equivalent in Matlab
1 次查看(过去 30 天)
显示 更早的评论
Hello Matlab comunity, my question is what would be the equivalent to FORTRAN POPPAR function in Matlab?
According to gnc webpage, POPPAR(I) returns parity of the integer I, i.e. the parity of the number of bits set ('1' bits) in the binary representation of I. It is equal to 0 if I has an even number of bits set, and 1 for an odd number of '1' bits.
Thank you!
0 个评论
采纳的回答
更多回答(1 个)
Walter Roberson
2021-7-9
bitget() can be faster.
I = randi([0 2^32-1], 1, 1, 'uint32')
timeit(@() mod(nnz(dec2bin(I)-'0'),2),0)
timeit(@() fold(@xor, dec2bin(I) - '0', 0), 0)
timeit(@() fold(@xor, bitget(I, 1:32), 0), 0)
timeit(@() mod(sum(bitget(I,1:32)),2),0)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fortran with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!