L
lefoot
Here is the problem.
The funtion "bitcount" has the parameter x( integer type, 4byte).
The "bitcount" should count the number of '1' from the binary
representation
of x.
But You shouldn't use either 'if' or 'else'. You're allowed to use
bitwise
operators such as '!, ~, ^, &, |, >>, <<'. You can use any local
variables,
constants, and '=' operator.
Preventing you from counting in brute-force manner such
as(x&1+x>>1&1+x>>2&1+...x>>30&1+x>>31&1), You have to count the bit
number within 40 operators.
This is one of my assignment, but I can't find any solution. A little
hint
would be great help for me. Waiting for your reply. Thanks.
The funtion "bitcount" has the parameter x( integer type, 4byte).
The "bitcount" should count the number of '1' from the binary
representation
of x.
But You shouldn't use either 'if' or 'else'. You're allowed to use
bitwise
operators such as '!, ~, ^, &, |, >>, <<'. You can use any local
variables,
constants, and '=' operator.
Preventing you from counting in brute-force manner such
as(x&1+x>>1&1+x>>2&1+...x>>30&1+x>>31&1), You have to count the bit
number within 40 operators.
This is one of my assignment, but I can't find any solution. A little
hint
would be great help for me. Waiting for your reply. Thanks.