COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Bitwise manipulation

• Email
• Follow

```how can u find whether a no has consecutive zero bits either in from
LSB or MSB.
if they exist in between, then what to do? plz clarify.

```
 0
Reply nehilparashar (24) 7/14/2007 8:27:30 PM

See related articles to this posting

```"Nehil" <nehilparashar@gmail.com> wrote in message
> how can u find whether a no has consecutive zero bits either in from
> LSB or MSB.
> if they exist in between, then what to do? plz clarify.
>
Take the binary complement of the number (~). Take two copies, and shift one
a bit (<<). Then AND (&, just one). If the answer is non-zero, you have
consecutive zero bits.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

```
 0
Reply regniztar (3128) 7/14/2007 9:02:28 PM

```On Jul 15, 2:02 am, "Malcolm McLean" <regniz...@btinternet.com> wrote:
> "Nehil" <nehilparas...@gmail.com> wrote in message
>
> news:1184444850.478621.170190@22g2000hsm.googlegroups.com...> how can u find whether a no has consecutive zero bits either in from
> > LSB or MSB.
> > if they exist in between, then what to do? plz clarify.
>
> Take the binary complement of the number (~). Take two copies, and shift one
> a bit (<<). Then AND (&, just one). If the answer is non-zero, you have
> consecutive zero bits.
>
> --
> Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm

Thanks for your answer. but the solution you suggested only tells true
or false, whether consecutive zero bits are there or not.

i need something different :
i want to know how many consecutive zero bits are there?
for exapmle :
let say arr[0] = 10; so bit representation will be (32-bit)

00000000 00000000 00000000 00001010

so answer should be => 29 from MSB and 1 from LSB.
Thanks.

```
 0
Reply nehilparashar (24) 7/14/2007 9:13:00 PM

```Nehil wrote:
> how can u find whether a no has consecutive zero bits either in from
> LSB or MSB.
> if they exist in between, then what to do? plz clarify.

Are you the same "Nehil" who is undertaking to write
a garbage collector for C?  If so, have you ever heard the

Yes, we all know that "A man's reach should exceed his
grasp," but perhaps by not quite so wide a span ...

--
Eric Sosman
esosman@ieee-dot-org.invalid
```
 0
Reply esosman2 (3096) 7/14/2007 9:30:17 PM

```On Jul 15, 2:30 am, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
> Nehil wrote:
> > how can u find whether a no has consecutive zero bits either in from
> > LSB or MSB.
> > if they exist in between, then what to do? plz clarify.
>
>      Are you the same "Nehil" who is undertaking to write
> a garbage collector for C?  If so, have you ever heard the
> advice "Walk before you run?"
>
>      Yes, we all know that "A man's reach should exceed his
> grasp," but perhaps by not quite so wide a span ...
>
> --
> Eric Sosman
> esos...@ieee-dot-org.invalid

===================================================================
Yes, i'm the same Nehil. :) but i could not understand your wordings.
i
came to this doubt in that project only. i designed a bitmap for each
page i allocate, and now want to know how many pages have been
allocated by knowing how many bits are there zero??

is this approach good?

```
 0
Reply nehilparashar (24) 7/14/2007 9:47:25 PM

```Nehil wrote:
>
> On Jul 15, 2:02 am, "Malcolm McLean" <regniz...@btinternet.com> wrote:
> > "Nehil" <nehilparas...@gmail.com> wrote in message
> >
> > news:1184444850.478621.170190@22g2000hsm.googlegroups.com...> how can u find whether a no has consecutive zero bits either in from
> > > LSB or MSB.
> > > if they exist in between, then what to do? plz clarify.
> >
> > Take the binary complement of the number (~). Take two copies, and shift one
> > a bit (<<). Then AND (&, just one). If the answer is non-zero, you have
> > consecutive zero bits.
> >
> > --
> > Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm
>
> Thanks for your answer. but the solution you suggested only tells true
> or false, whether consecutive zero bits are there or not.
>
> i need something different :
> i want to know how many consecutive zero bits are there?
> for exapmle :
> let say arr[0] = 10; so bit representation will be (32-bit)
>
> 00000000 00000000 00000000 00001010
>
> so answer should be => 29 from MSB and 1 from LSB.

/* BEGIN new.c */

#include <stdio.h>

#define N               10U
#define str(s)          # s
#define xstr(s)         str(s)

void consecutive_zero_bits(unsigned n, unsigned *most, unsigned *least);

int main(void)
{
unsigned most, least;

consecutive_zero_bits(N, &most, &least);
puts(xstr(N));
printf("%u from MSB and %u from LSB.\n", most, least);
return 0;
}

void consecutive_zero_bits(unsigned n, unsigned *most, unsigned *least)
{

count = 0;
if( (mask & n) == 0) {
++count;
} else {
*least = count;
break;
}
}
count = 0;
for (mask = (0u - 1) / 2 + 1; mask != 0; mask /= 2) {
if( (mask & n) == 0) {
++count;
} else {
*most = count;
break;
}
}
}

/* END new.c */

--
pete
```
 0
Reply pfiland (6614) 7/14/2007 9:55:34 PM

```"Nehil" <nehilparashar@gmail.com> wrote in message
> On Jul 15, 2:30 am, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
>> Nehil wrote:
>> > how can u find whether a no has consecutive zero bits either in from
>> > LSB or MSB.
>> > if they exist in between, then what to do? plz clarify.
>>
>>      Are you the same "Nehil" who is undertaking to write
>> a garbage collector for C?  If so, have you ever heard the
>> advice "Walk before you run?"
>>
>>      Yes, we all know that "A man's reach should exceed his
>> grasp," but perhaps by not quite so wide a span ...
>>
>> --
>> Eric Sosman
>> esos...@ieee-dot-org.invalid
>
> ===================================================================
> Yes, i'm the same Nehil. :) but i could not understand your wordings.
> i
> came to this doubt in that project only. i designed a bitmap for each
> page i allocate, and now want to know how many pages have been
> allocated by knowing how many bits are there zero??
>
> is this approach good?
>
A garbage collector, let alone an efficient garbage collector, is a very
difficult routine to write. If you can't even do basic bit manipulation - no
shame on you, we were all beginners at some time - then there is no way you
are going to achieve a garbage collector, except by some miracle.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

```
 0
Reply regniztar (3128) 7/15/2007 8:33:52 AM

```On Jul 15, 1:33 pm, "Malcolm McLean" <regniz...@btinternet.com> wrote:
> "Nehil" <nehilparas...@gmail.com> wrote in message
>
>
> > On Jul 15, 2:30 am, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
> >> Nehil wrote:
> >> > how can u find whether a no has consecutive zero bits either in from
> >> > LSB or MSB.
> >> > if they exist in between, then what to do? plz clarify.
>
> >>      Are you the same "Nehil" who is undertaking to write
> >> a garbage collector for C?  If so, have you ever heard the
> >> advice "Walk before you run?"
>
> >>      Yes, we all know that "A man's reach should exceed his
> >> grasp," but perhaps by not quite so wide a span ...
>
> >> --
> >> Eric Sosman
> >> esos...@ieee-dot-org.invalid
>
> > ===================================================================
> > Yes, i'm the same Nehil. :) but i could not understand your wordings.
> > i
> > came to this doubt in that project only. i designed a bitmap for each
> > page i allocate, and now want to know how many pages have been
> > allocated by knowing how many bits are there zero??
>
> > is this approach good?
>
> A garbage collector, let alone an efficient garbage collector, is a very
> difficult routine to write. If you can't even do basic bit manipulation - no
> shame on you, we were all beginners at some time - then there is no way you
> are going to achieve a garbage collector, except by some miracle.
>
> --
> Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm

However i've developed it myself and it is working efficiently. it was
bit manipulation that makes me nervous while thinking logic for it.
but i'll practice for it.

the allocator and de-allocator both r working fine.
Actually, the problem i asked to find some effecient solution for it.
by linear searching, i'd already done it.

thnkas all.

```
 0
Reply nehilparashar (24) 7/15/2007 12:34:48 PM

```Nehil wrote:
> how can u find whether a no has consecutive zero bits either in from
> LSB or MSB.

What does "either in from LSB or MSB" mean?

> if they exist in between, then what to do?

Between what?

> plz clarify.

I suggest that _you_ clarify.

--
```
 0

8 Replies
60 Views

Similar Articles

12/8/2013 1:07:59 AM
[PageSpeed]

Similar Artilces:

Text Manipulation
I spend a lot of time using Input > Create Automatic Numbering Object . . . to create references of the form : Proposition 3.7.9. The relevant part of the cell expression is something like TextData[{ "Propostion\[NonBreakingSpace]", CounterBox["Title", "foo"], ".", CounterBox["Section", "foo"], ".", CounterBox["Proposition", "foo"] }] Here "foo" is a cell label and "Proposition" is a defined cell style. I would like a more efficient way

matrix manipulation?
Dear All I have a column matrix 'x' of the size 109760*1 that I have split it into 343 column vectors each of the size 320*1 as the following: ->f=enframe(x,320); For each of these segments, I mean xi (i from 1 to 343) I am trying to find its estimation through linear prediction like the following : ->ai=lpc(xi,4); ->est_xi=filter([0 -ai(2:end)],1,xi); To this end, I have an estimated vector est_xi of the size 320*1 . At the end, I need to put these estimated segments back again in another 109760*1 column matrix to obtain an overall estimated one. Can you please let me know ho

Matrix manipulation!
Hi everyone, I am writing a function that has to do some matrix manipulation. I have a matrix X and a vector REMOVE. In each iteration, I have to remove the columns in X indexed by entries in the REMOVE vector, do some stuff with the remaining matrix. Then at the end of the iteration, I have to put back the columns that I have removed. For example: Matrix X, vector REMOVE=[2;3;4]. That means I have to remove columns 2,3,4 for now to get a new matrix X'. And then put columns 2,3,4 back to where they were. Can someone show me an efficient way of doing it? The matrix is of decent size. Thanks a lot. Minh So you suggested making a copy of X and work on it? The matrix I have is 2000*2000 and the size of REMOVE can range from anywhere between 0 to 500. Do you think in terms of memory this is good? Thanks for your quick response. Minh Pham <ptuanminh@gmail.com> wrote in message <1472005717.187056.1288194448426.JavaMail.root@gallium.mathforum.org>... > Hi everyone, > I am writing a function that has to do some matrix manipulation. I have a matrix X and a vector REMOVE. In each iteration, I have to remove the columns in X indexed by entries in the REMOVE

list manipulation
;740 m AMSL. > Date: Thu, 10 Feb 2011 05:19:50 -0500 > From: andrea.dellapatria@gmail.com > Subject: list manipulation > To: mathgroup@smc.vnet.net > > hello, I need help about the following question: > > I have two N-dimensional lists: > > list1={x1,x2,...,xN} list2={y1,y2,...,yN} > > How to create the N-dimrnsional list: list3={{x1,y1},{x2,y2},..., > {xN,yN}} ? > > I've tried so hard but I didn't work it out! > > Tanks in advance for your support > > Andrea > On Feb 10, 5:19 am...-dimrnsional list: list3={{x1,y1},{x2,y2},..., {xN,yN}} ? I've tried so hard but I didn't work it out! Tanks in advance for your support Andrea Try list3 = MapThread[List, {list1, list2}] -Tomas > Date: Thu, 10 Feb 2011 05:19:50 -0500 > From: andrea.dellapatria@gmail.com > Subject: list manipulation > To: mathgroup@smc.vnet.net > > hello, I need help about the following question: > > I have two N-dimensional lists: > > list1={x1,x2,...,xN} list2={y1,y2,...,yN} > > How to create the N-dimrnsional list: list3

Datafile Manipulation
Hi, I'm trying to write a shell which will assess a list of student's grades. The data file consists of the following... 2068344 8 6 3 8 2 8 2068943 9 7 3 7 3 7 The large numbers being the student ID, the small numbers being the mark on a certain question. My overall target is to output the student ID and the overall percentage. i.e. 2068344 78% 2068943 47% I have run into a problem in that when performing the mathematics on the file (at this stage the addition of the marks, leading to working out the percentage), I can not dfferentiate between each individual student, leaving me w

file Manipulation
hello is there any method using VB to change txt files to excel files help me

cell manipulation
I need a function to manipulate a cell and concatanates the results into another cell. An example of what it's supposed to do: function [out]=cellMix(input) input= {{'abc', 'lks', 'oiw'}, {'tra', 'asdasd', 'wex'}, [2 3 1]} %input always 2 sub-cells %and one vector of doubles output= {'atra2', 'lasdasd3', 'owex1'} So this function takes the first letter of the 1st sub-cell, takes the whole 2nd sub-cells, and finally the numbers in the vector. Then it concatanates them into the new output cell. I forgot to

Expression manipulation
user of your Presentations package may I suggest a possible interface addition to a future release. It would be nice to have your additional manipulations (discussed below by you) in a new palette "PresentationsAlgebraicManipulation". This would supplement the standard release palette AlgebraicManipulation and enable use of one very interactive style of expression manipulation. As I write this it strikes me that this might not be a very easy thing to do and I would appreciate your response. This thought was prompted by John Fulz's contribution to this thread. From: jfultz@wolfram.com Subject: Expression manipulation Best wishes, Syd Syd Geraghty B.Sc, M.Sc. sydgeraghty@mac.com My System Mathematica 6.0.2.1 for Mac OS X x86 (64 - bit) (March 13, 2008) MacOS X V 10.5.2 MacBook Pro 2.33 Ghz Intel Core 2 Duo 2GB RAM On May 15, 2008, at 3:51 AM, David Park wrote: > David, > > You should be able to do all the manipulations using Mathematica. > You should > learn how to use rule based programming, commands such as MapAt, > Apart, > Together, Cancel. HoldForm