Re: nr of bits set to "1" in a byte
From: Richard Heathfield (dontmail_at_address.co.uk.invalid)
Date: 12/20/03
- Next message: AmateurScripter: "How should I start learning?"
- Previous message: Thomas Matthews: "Re: Caps convention."
- In reply to: Sidney Cadot: "Re: nr of bits set to "1" in a byte"
- Next in thread: Robert Stankowic: "Re: nr of bits set to "1" in a byte"
- Reply: Robert Stankowic: "Re: nr of bits set to "1" in a byte"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: AmateurScripter: "How should I start learning?"
- Previous message: Thomas Matthews: "Re: Caps convention."
- In reply to: Sidney Cadot: "Re: nr of bits set to "1" in a byte"
- Next in thread: Robert Stankowic: "Re: nr of bits set to "1" in a byte"
- Reply: Robert Stankowic: "Re: nr of bits set to "1" in a byte"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|