Checking bit state of lpt port binary
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 开发者_如何学JAVAinstruction with binary values?
for example while bit 3 of 00100100 is 0 then do something.
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.
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 ;)
精彩评论