Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Does bit operation always work more efficiently than math operation?

Reply
Thread Tools

Does bit operation always work more efficiently than math operation?

 
 
pete
Guest
Posts: n/a
 
      03-01-2006
CBFalconer wrote:
>
> pete wrote:
> > david ullua wrote:
> >

> ... snip ...
> >>
> >> int column = 0;
> >> //other codes .....
> >> do {
> >> putchar(' ');
> >> column++;
> >> } while (column & 07);

> >
> > while ((column | ~7U) == 0);

>
> Looks like another way of spelling "once".


while ((column & ~7U) == 0);

--
pete
 
Reply With Quote
 
 
 
 
Micah Cowan
Guest
Posts: n/a
 
      03-01-2006
pete <(E-Mail Removed)> writes:

> CBFalconer wrote:
> >
> > pete wrote:
> > > david ullua wrote:
> > >

> > ... snip ...
> > >>
> > >> int column = 0;
> > >> //other codes .....
> > >> do {
> > >> putchar(' ');
> > >> column++;
> > >> } while (column & 07);
> > >
> > > while ((column | ~7U) == 0);

> >
> > Looks like another way of spelling "once".

>
> while ((column & ~7U) == 0);


Why is this better than:

while (column & 07);

which is what OP wrote in the first place?
 
Reply With Quote
 
 
 
 
tedu
Guest
Posts: n/a
 
      03-01-2006
Micah Cowan wrote:
> pete <(E-Mail Removed)> writes:
> > while ((column & ~7U) == 0);

>
> Why is this better than:
>
> while (column & 07);
>
> which is what OP wrote in the first place?


it's a replacement for (column <= 7); the original is not.

 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      03-01-2006
tedu wrote:
>
> Micah Cowan wrote:
> > pete <(E-Mail Removed)> writes:
> > > while ((column & ~7U) == 0);

> >
> > Why is this better than:
> >
> > while (column & 07);
> >
> > which is what OP wrote in the first place?

>
> it's a replacement for (column <= 7); the original is not.


If column was unsigned, then it would be a valid replacement.
It was the best I could do otherwise.

--
pete
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
Bit more DOF, bit more light, bit better? Dudley Hanks Digital Photography 9 03-29-2009 09:46 PM
64-bit XP OS uses memory more efficiently than 32-bit? Spin Windows 64bit 3 03-07-2008 03:31 AM
64-bit XP OS uses memory more efficiently than 32-bit? Spin Computer Support 6 03-06-2008 08:48 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit,Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new! Ionizer Computer Support 1 01-01-2004 07:27 PM



Advertisments