且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Matlab中的整数列表的汉明权重

更新时间:2023-02-27 11:09:51

这有点棘手,但可以:

res = sum( dec2bin(a).' == '1' );

它将a转换为二进制表示形式,查看该表示形式中有多少字符是'1',然后将这些数字相加.

It converts a to binary representation, looks at how many characters in that representation are '1', and sums up those numbers.