Set and Clear bits in TABLE values (Function)

Set and Clear bits in TABLE values (Function)

Here are 2 functions to set and clear a bit in a given TABLE value.

' functions to set and clear bits in TABLE

FUNCTION set_table_bit(index, bit AS INTEGER)
  DIM pattern AS INTEGER
  pattern = 1 << bit
  TABLE(index, TABLE(index) OR pattern)
ENDFUNC

FUNCTION clear_table_bit(index, bit AS INTEGER)
  DIM pattern AS INTEGER
  pattern = NOT (1 << bit)
  TABLE(index, TABLE(index) AND pattern)
ENDFUNC

 

In the main program it is then set_table_bit(100, 4) to set bit 4 of table 100.

 

    • Related Articles

    • A Trio BASIC Function Library for calculating min, max and average

      The attached library has 10 functions; result = compare_2(v1, v2) preset_max(index, value) preset_min(index, value) compare_max(index, value) compare_min(index, value) value = read_max_register(index) value = read_min_register(index) And for the ...
    • Timed ramps and dwells - a FUNCTION example

      Functions to make timed position ramps and dwells. For example as might be used in a blow moulding controller. ' Function library to support timed ramps ' 'Declare a universal value to hold the table index DIM tab_index AS INTEGER ' Set up a linear ...
    • AN-430 Function to set CONTROLWORD values

      In some device, such as Inverters, the CONTROL WORD have to be set to a different value to enable the drive. The Ethercat Function $7E can do this
    • AN-389 VRSTRING 16 bits TrioBASIC Function

      VRSTRING combines the contents of an array of VR() variables so that they can be printed as a text string or used as part of a STRING variable. This document explains with an example code.
    • How many TABLE values are saved to Flash in the MC6N?

      The default is none (only VRs are stored; FLASH_DATA = 0) However 64000 will be stored when FLASH_DATA is set to 1   See the Trio BASIC help for FLASH_DATA.