开发者

Checking bit state of lpt port binary

开发者 https://www.devze.com 2023-04-12 17:04 出处:网络
I\'ve part of code which is checking input pins of lpt port, but using decimal values: while (PortAccess.Input(889) == 120)

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 ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消