relations/identities

Discussion in 'C Programming' started by aarklon@gmail.com, Dec 7, 2007.

  1. Guest

    Hi all,

    the following are the relations involving modulus operator that i have
    found working

    1) a = a %b + (a/b) * b ; for integral values of a and b

    2) w % n = w & (n-1);

    can any one give more examples for relations like this ...????
     
    , Dec 7, 2007
    #1
    1. Advertising

  2. In article <>,
    <> wrote:

    >2) w % n = w & (n-1);


    You need a constraint on n here. 5 % 3 = 2 but 5 & 2 = 0.

    -- Richard
    --
    :wq
     
    Richard Tobin, Dec 7, 2007
    #2
    1. Advertising

  3. Guest

    On Dec 7, 1:42 pm, (Richard Tobin) wrote:
    > In article <>,
    >
    > <> wrote:
    > >2) w % n = w & (n-1);

    >
    > You need a constraint on n here. 5 % 3 = 2 but 5 & 2 = 0.
    >
    > -- Richard
    > --
    > :wq


    sorry i made a mistake

    it should be rather w % (n-1) = w & n;

    now
    5 % 2 = 1
    5 & 3 = 1
     
    , Dec 8, 2007
    #3
  4. wrote:
    > (Richard Tobin) wrote:
    > > <> wrote:
    > > > 2) w % n = w & (n-1);

    > >
    > > You need a constraint on n here.


    And w.

    > > 5 % 3 = 2 but 5 & 2 = 0.

    >
    > sorry i made a mistake


    Your correction was a much bigger mistake.

    > it should be rather w % (n-1) = w & n;


    Even on its own terms this makes no sense. [Try w == n.]

    --
    Peter
     
    Peter Nilsson, Dec 8, 2007
    #4
  5. Guest

    On Dec 8, 2:30 am, Peter Nilsson <> wrote:
    > wrote:
    > > (Richard Tobin) wrote:
    > > > <> wrote:
    > > > > 2) w % n = w & (n-1);

    >
    > > > You need a constraint on n here.

    >
    > And w.
    >
    > > > 5 % 3 = 2 but 5 & 2 = 0.

    >
    > > sorry i made a mistake

    >
    > Your correction was a much bigger mistake.
    >
    > > it should be rather w % (n-1) = w & n;

    >
    > Even on its own terms this makes no sense. [Try w == n.]


    let us add a constraint n < w and n >= 2
     
    , Dec 8, 2007
    #5
  6. said:

    > On Dec 8, 2:30 am, Peter Nilsson <> wrote:
    >> wrote:
    >> > (Richard Tobin) wrote:
    >> > > <> wrote:
    >> > > > 2) w % n = w & (n-1);

    >>
    >> > > You need a constraint on n here.

    >>
    >> And w.
    >>
    >> > > 5 % 3 = 2 but 5 & 2 = 0.

    >>
    >> > sorry i made a mistake

    >>
    >> Your correction was a much bigger mistake.
    >>
    >> > it should be rather w % (n-1) = w & n;

    >>
    >> Even on its own terms this makes no sense. [Try w == n.]

    >
    > let us add a constraint n < w and n >= 2


    Okay. Let n = 79, and let w = 83. w % n is 4, but w & (n - 1) is 66 if my
    bit-twiddling is right. Last I checked, 4 != 66.

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
     
    Richard Heathfield, Dec 8, 2007
    #6
  7. James Kuyper Guest

    wrote:
    > Hi all,
    >
    > the following are the relations involving modulus operator that i have
    > found working

    ....
    > 2) w % n = w & (n-1);
    >
    > can any one give more examples for relations like this ...????


    The second relationship is true only when n is a power of 2.
     
    James Kuyper, Dec 8, 2007
    #7
  8. Guest

    On Dec 8, 7:57 am, Richard Heathfield <> wrote:
    > said:
    >
    >
    >
    > > On Dec 8, 2:30 am, Peter Nilsson <> wrote:
    > >> wrote:
    > >> > (Richard Tobin) wrote:
    > >> > > <> wrote:
    > >> > > > 2) w % n = w & (n-1);

    >
    > >> > > You need a constraint on n here.

    >
    > >> And w.

    >
    > >> > > 5 % 3 = 2 but 5 & 2 = 0.

    >
    > >> > sorry i made a mistake

    >
    > >> Your correction was a much bigger mistake.

    >
    > >> > it should be rather w % (n-1) = w & n;

    >
    > >> Even on its own terms this makes no sense. [Try w == n.]

    >
    > > let us add a constraint n < w and n >= 2

    >
    > Okay. Let n = 79, and let w = 83. w % n is 4, but w & (n - 1) is 66 if my
    > bit-twiddling is right. Last I checked, 4 != 66.


    I have seen this result in one book, but i don't remember it
    correctly.I think it is in your book "C unleashed"
     
    , Dec 8, 2007
    #8
  9. Guest

    On Dec 8, 10:00 am, wrote:
    > w % n = w & (n-1);
    > I have seen this result in one book, but i don't remember it correctly.


    You remembered it wrong.

    The formula above is guaranteed only if n is a power of 2.
    That is, n must be 1, or 2, or 4, or 8, or 16, or 32...
     
    , Dec 8, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Johansen

    Weird ASP.NET identities problem. Help.

    Peter Johansen, May 21, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    368
    Peter Johansen
    May 21, 2004
  2. Corey Ellsworth

    COM Identities in ASP.NET

    Corey Ellsworth, May 5, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    368
    Paul Clement
    May 6, 2005
  3. =?Utf-8?B?TWFrc2ltIEl6YnJvZGlu?=

    Passing authenticated identities between tiers in a distributed ap

    =?Utf-8?B?TWFrc2ltIEl6YnJvZGlu?=, Apr 3, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    429
    =?Utf-8?B?TWFrc2ltIEl6YnJvZGlu?=
    Apr 3, 2006
  4. Maksim Izbrodin
    Replies:
    0
    Views:
    137
    Maksim Izbrodin
    Apr 3, 2006
  5. Anthony Yott

    custom app pools with domain identities

    Anthony Yott, Aug 23, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    92
    Anthony Yott
    Aug 23, 2006
Loading...

Share This Page