masks

Discussion in 'C Programming' started by lezard, Jun 1, 2005.

  1. lezard

    lezard Guest

    Hello :)

    i_before = 1;
    i_after = i_before and a mask;
    i_before = (i_after & 0x7) | 0x40; // then i_before == 1

    I don't find what mask is applied to i_before at the second line. :-(
    Can someone help me?

    --
    Lezard
     
    lezard, Jun 1, 2005
    #1
    1. Advertisements

  2. lezard

    Richard Bos Guest

    lezard <> wrote:

    > i_before = (i_after & 0x7) | 0x40; // then i_before == 1


    Regardless of anything else, this is impossible. Think about it. How
    could _anything_ | 0x40 ever be 1?

    Richard
     
    Richard Bos, Jun 1, 2005
    #2
    1. Advertisements

  3. lezard

    pete Guest

    lezard wrote:
    >
    > Hello :)
    >
    > i_before = 1;
    > i_after = i_before and a mask;
    > i_before = (i_after & 0x7) | 0x40; // then i_before == 1
    >
    > I don't find what mask is applied to i_before at the second line. :-(
    > Can someone help me?


    Any odd number value for mask, will make the comment true.
     
    pete, Jun 1, 2005
    #3
  4. lezard

    pete Guest

    pete wrote:
    >
    > lezard wrote:
    > >
    > > Hello :)
    > >
    > > i_before = 1;
    > > i_after = i_before and a mask;
    > > i_before = (i_after & 0x7) | 0x40; // then i_before == 1
    > >
    > > I don't find what mask is applied to i_before at the second line. :-(
    > > Can someone help me?

    >
    > Any odd number value for mask, will make the comment true.


    Actually, as Richard Bos stated, there is no value
    which when bitwise ORed with 0x40, yields 1.
     
    pete, Jun 1, 2005
    #4
  5. In article <>, pete <> writes:
    > pete wrote:
    > >
    > > lezard wrote:
    > > >
    > > > i_before = 1;
    > > > i_after = i_before and a mask;
    > > > i_before = (i_after & 0x7) | 0x40; // then i_before == 1
    > > >
    > > > I don't find what mask is applied to i_before at the second line. :-(
    > > > Can someone help me?

    > >
    > > Any odd number value for mask, will make the comment true.

    >
    > Actually, as Richard Bos stated, there is no value
    > which when bitwise ORed with 0x40, yields 1.


    True, though there could be a *variable* which, after being bitwise-
    ORed with 0x40, evaluates to 1. It would have to have fewer than
    seven value bits, so it would have to be a bitfield; and since in the
    OP's posted code i_before cannot be the identifier for a bit- field
    (which must be part of a struct or union, and so must be the operand
    of the "." or "->" operator), it would have to be a macro for one.

    (At least I think that's right; corrections cheerfully accepted.)

    --
    Michael Wojcik

    Art is our chief means of breaking bread with the dead ... but the social
    and political history of Europe would be exactly the same if Dante and
    Shakespeare and Mozart had never lived. -- W. H. Auden
     
    Michael Wojcik, Jun 2, 2005
    #5
    1. Advertisements

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. Gianni Mariani
    Replies:
    0
    Views:
    412
    Gianni Mariani
    Jan 13, 2005
  2. bobrics
    Replies:
    2
    Views:
    944
    Flash Gordon
    Mar 21, 2006
  3. Dave

    shifts and masks

    Dave, Jun 3, 2006, in forum: C Programming
    Replies:
    4
    Views:
    592
    Malcolm
    Jun 4, 2006
  4. Dave

    replace bitfields with shifts and masks

    Dave, Jun 4, 2006, in forum: C Programming
    Replies:
    3
    Views:
    462
    Chris Torek
    Jun 4, 2006
  5. Masks: Why?

    , Jun 5, 2006, in forum: C Programming
    Replies:
    10
    Views:
    889
  6. mrstephengross
    Replies:
    3
    Views:
    554
    James Kanze
    May 10, 2007
  7. Wojtek

    masks and enums

    Wojtek, Jul 24, 2007, in forum: Java
    Replies:
    21
    Views:
    1,047
    Wojtek
    Jul 31, 2007
  8. RazvanD

    Power of two alignment (bit masks)

    RazvanD, Apr 29, 2008, in forum: C Programming
    Replies:
    1
    Views:
    1,012
    christian.bau
    Apr 29, 2008
Loading...