Syntax-Query get one of the bits after PortIn or BusIn

06 Dec 2011

Hi all, After reading the port, I need to use "pins"as a 4 bit binary number,

PortIn p(Port0, 0x00000C30);

pins=p.read();

I'm using C to compile.

1. Define Binary : Which type should I define the "pins" as? Is that int?

2. Fetch 1 bit from (int?): And after that how can I fetch each bit from the 4 bits. Should I write like pins[0],pins[1],etc

10 Dec 2011

something like this?

int pins = p.read();
int result = 0, s=3;
for( int mask=0x00000C30; mask; mask>>=1, pins>>=1)
  if( mask&1)
  {
    result |= (pins&1) << s;
    --s;
  }

Or just use BusIn, it returns the bits in the order you've chosen the pins.