In SX Microcontrollers, SX/B Compiler and SX-Key Tool, JonnyMac wrote: I'm working on a "Life" program for the SX (using an 8x8 array of LEDs) and need to do bit indexing as well. Here's function that I have started with; it may be helpful to you. [code]BITVAL FUNC 1, 2, 3 . . . ' Use: value = BITVAL someVal, position ' -- "someVal" can be a byte or word 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[/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=161044#m161237 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)