Mistake in the site's FAQ

This is a discussion on Mistake in the site's FAQ within the C Programming forums, part of the General Programming Boards category; Originally Posted by quzah Well, if it was portable, it would in theory be faster than the modulus version. Bitwise ...

  1. #16
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    Quote Originally Posted by quzah
    Well, if it was portable, it would in theory be faster than the modulus version. Bitwise operators tend to be faster than division and modulus. That's why people used to use shifting for division by two instead of the division operator.


    Quzah.
    I agree with that, I had actually thought of it after I posted, but didn't bother editting my post as I'm sure someone has already seen it.
    Sent from my iPadŽ

  2. #17
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    I've tried ANDing with 1 and Solaris running on SPARC and NetBSD running on i386, and both work indentically.

  3. #18
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Good for you. I don't think anyone here really cares though. But if you're still unsure, guess what? Lots of people here use "void main" and stuff like "fflush( stdin )". However, that doesn't mean they're right.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #19
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    The AND trick works on any system that uses 2's complement negative numbers or a simpe sign bit. Which is most of today's systems, but there are some 1's complement around, where the trick fails for negative numbers.

    But it's completely unnecessary, because every compiler worth its salt will replace (x % 2) by (x & 1) if it knows that the platform doesn't use 1's complement.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wiki FAQ
    By dwks in forum A Brief History of Cprogramming.com
    Replies: 192
    Last Post: 04-29-2008, 01:17 PM
  2. Shareware Sites - Updating Them
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 11-11-2002, 01:58 AM
  3. FAQ Check/Lock
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-15-2002, 11:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21