Connecting Tech Pros Worldwide Help | Site Map

read bits from unsigned int

Newbie
 
Join Date: Sep 2009
Posts: 22
#1: Oct 17 '09
Hi all,

i am a little confused about reading some bits form unsigend int, so if i have the following code:
Expand|Select|Wrap|Line Numbers
  1. unsigned int a (5); // ......101
  2. bool b0;
  3. bool b1;
  4. bool b2;
  5.  
  6.  
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's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,156
#2: Oct 17 '09

re: read bits from unsigned int


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