Re: nr of bits set to "1" in a byte

From: Richard Heathfield (dontmail_at_address.co.uk.invalid)
Date: 12/20/03


Date: Sat, 20 Dec 2003 18:31:48 +0000 (UTC)

Sidney Cadot wrote:

> Jarno A Wuolijoki wrote:
>
>> On Sat, 20 Dec 2003, Sidney Cadot wrote:
>>
>> B> One obvious solution that wasn't mentioned so far:
>>
>>>unsigned bits(const unsigned n)
>>>{
>>> return n ? n&1 + bits(n>>1) : 0;
>>>}
>>
>>
>> I'm not a fan of excessive parenthesizing either, but I would still add
>> a couple of them there..
>
> You're right, it should be
>
> unsigned bits(const unsigned n)
> {
> return n ? (n&1) + bits(n>>1) : 0;
> }
>
> That should teach me to excrete untested code.

This English idiom, rather like "head over tails", is head over tails, (or
rather, it's tails over heads). The meaning you intend to convey (and yes,
you've said it correctly; this isn't an English lesson!) is that it ought
to teach you /not/ to publish (is that a fair substitute? <g>) untested
code.

In fact, though, it will do no such thing. At least, the lesson didn't work
for the rest of us, so I don't see why it should work for you! :-)

-- 
Richard Heathfield : binary@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton


Relevant Pages

  • Re: Cantor Confusion
    ... No I simply state that the diagonal proof fails in case of the tree. ... The single root node is the beginning of all paths. ... Each path has a head node and a tail consisting of everything else. ... So how many tails has one head? ...
    (sci.math)
  • Re: Me and David C. Ullrich
    ... > Eldon, it wasn't decided to make a "tails" statement. ... At least one is a head, ... The timing of this choosing is significant. ...
    (sci.math)
  • Re: check out this 77 jmp 2204 50watt - need advise..(LINK TO PICTURES)
    ... has head and tails). ... and the other is flipped (i.e. tails). ... when comparing the boards of our amps, ... it seems like one board is facing up, and the other is facing down. ...
    (alt.guitar.amps)
  • Re: docking my rottis tail, yes or no, she is 6mos old
    ... It's hanging, horizontal, curved up to the head and coiled up to the back ... Siberian Huskies should not have curly ... tails and Mackenzie River Huskies do not have curly tails. ... Akita, which is not a husky, or the Basenji, which is so not ...
    (rec.pets.dogs.behavior)
  • Re: check out this 77 jmp 2204 50watt - need advise..(LINK TO PICTURES)
    ... has head and tails). ... and the other is flipped (i.e. tails). ... when comparing the boards of our amps, ... it seems like one board is facing up, and the other is facing down. ...
    (alt.guitar.amps)