In SX Microcontrollers, SX/B Compiler and SX-Key Tool, tdg8934 wrote: JonnyMac wrote this BITVAL function that may do what you are asking. Take a look at it in my example sniplet: [code] data1 VAR Word tmpW1 VAR Word tmpW2 VAR Word tmpB1 VAR Byte tmpB2 VAR Byte I VAR Byte J VAR Byte value VAR Byte Check SUB BITVAL FUNC 1, 2, 3 'Thanks to JonnyMac for these cool functions! ' Use: value = BITVAL someVal, position ' -- "someVal" can be a byte or word FUNC BITVAL IF __PARAMCNT = 2 THEN ' byte passed? tmpW1 = __PARAM1 ' get byte value tmpB1 = __PARAM2 ' get bit position ELSE ' word passed tmpW1 = __WPARAM12 ' word was passed tmpB1 = __PARAM3 ' get bit position ENDIF tmpB2 = 0 ' assume cleared IF tmpB1 >= 0 THEN ' position value legal? IF tmpB1 <= 15 THEN tmpW2 = 1 << tmpB1 ' create bit mask tmpW2 = tmpW2 & tmpW1 ' clear other bits IF tmpW2 > 0 THEN ' if not zero tmpB2 = 1 ' bit was 1 ENDIF ENDIF ENDIF RETURN tmpB2 ENDFUNC Check: For I = 0 to 15 value = BITVAL data1, I IF value = 1 THEN 'Do something here ELSE 'Do something different here ENDIF NEXT [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=268167#m268324 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)