Checking bit state of lpt port binary

543 views Asked by At

I've part of code which is checking input pins of lpt port, but using decimal values:

while (PortAccess.Input(889) == 120)

How to use this instruction with binary values?

for example while bit 3 of 00100100 is 0 then do something.

2

There are 2 answers

0
Elfoc On BEST ANSWER

Ok, so i've done this, because tafa solution wasn't working and i couldn't make it work:

   var PortValue = Convert.ToString(PortAccess.Input(889), 2).PadLeft(8, '0');
   PortV.Text = PortValue;
   while (PortV.Text[3].ToString() == "1")
   {
   //some code
   }

It's probably not good solution, but it's working ;)

2
tafa On

See Convert.ToInt32(string value, int fromBase)

while((value & Convert.ToInt32("00000100", 2)) == 0)

Or since we know the third bit is for (2^2)

while((value & 0x0004) == 0)

is also a clear enough piece of code, I guess.