更新时间: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.