Path: news.mathworks.com!not-for-mail
From: "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: count number of
Date: Wed, 30 Jul 2008 09:30:05 +0000 (UTC)
Organization: Ricardo UK Ltd
Lines: 18
Message-ID: <g6pcat$fn0$1@fred.mathworks.com>
References: <3817980.1217390262927.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1217410205 16096 172.30.248.37 (30 Jul 2008 09:30:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 30 Jul 2008 09:30:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 43398
Xref: news.mathworks.com comp.soft-sys.matlab:482591



bogfrog <jmcgraw@rcn.com> wrote in message 
<3817980.1217390262927.JavaMail.jakarta@nitrogen.mathforum.o
rg>...
> How would I do a bitcount in matlab?
> 
> For example, say I have the unsigned 8 bit integer 170, 
which is '10101010'.  Is there a function to count that it 
has 4 "on" (1) bits?
> 
> Thanks.

>> sum(dec2bin(170)-'0')

ans =

     4