|Pathologically Eclectic Rubbish Lister|
Re^4: Efficient bit counting with a twist.by BrowserUk (Pope)
|on Jun 01, 2013 at 09:49 UTC||Need Help??|
What is going on here?
I tweaked your code by adding a couple of extra print statements:
And when I run it I get this output:
hex converts the string '0xff' to a number which you store in $mask;
unpack expects a string, so perl helpfully converts the number stored in $mask to a string in the default decimal representation '255'.
You are counting the bits in that 3 byte string.
To count the bits in the number, you need to tell perl that you want the binary representation of that number:
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.