xsharp.eu • Read individual bits from a byte in VO
Page 1 of 1

Read individual bits from a byte in VO

Posted: Thu Oct 08, 2020 1:11 pm
by DPEETERS
Hi All,

I need to read the individual state of a bit , can sombody help me on this subject.

thanks,
dirk

Read individual bits from a byte in VO

Posted: Thu Oct 08, 2020 2:04 pm
by SHirsch
Hello Dirk,

a sample

Code: Select all

LOCAL n AS INT
   
n := 3
IF _AND(n,0x01) > 0  //true
   ?"Bit0"
ENDIF
IF _AND(n,0x02) > 0   //true
   ?"Bit1"
ENDIF
IF _AND(n,0x04) > 0  //false
   ?"Bit2"
ENDIF
Stefan

Read individual bits from a byte in VO

Posted: Thu Oct 08, 2020 2:06 pm
by SHirsch
Hi Dirk,

if you like shifting bits

Code: Select all

   LOCAL n AS INT
   
   n := 3
   IF _AND(n,1) > 0  //true
      ?"Bit0"
   ENDIF
   IF _AND(n>>1,1) > 0 //true
      ?"Bit1"
   ENDIF
   IF _AND(n>>2,1) > 0  //false
      ?"Bit2"
   ENDIF
Stefan

Read individual bits from a byte in VO

Posted: Thu Oct 08, 2020 2:07 pm
by DPEETERS
Hi Stefan,

thanks for the reply i give it a try.

regards,
dirk