read bits from unsigned int

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mar11
    New Member
    • Sep 2009
    • 38

    read bits from unsigned int

    Hi all,

    i am a little confused about reading some bits form unsigend int, so if i have the following code:
    Code:
    unsigned int a (5); // ......101
    bool b0;
    bool b1;
    bool b2;
    how can i read each bit form a and store it in b0, b1, b2 as following:
    b0 =1;
    b1=0;
    b2=1;

    thanks a lot in advance
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Look up the bitwise operators. You can use a bitwise and to separate out the value of a single bit.

    Comment

    Working...