Bit-Wise Operators - Galil Motion Control DMC-1000 User Manual

Table of Contents

Advertisement

COUNT=COUNT+2
RESULT=_TPX-(@COS[45]*40)
TEMP=@IN[1]&@IN[2]
The mathematical operators & and | are bit-wise operators. The operator, &, is a Logical And. The
operator, |, is a Logical Or. These operators allow for bit-wise operations on any valid DMC-1000
numeric operand, including variables, array elements, numeric values, functions, keywords, and
arithmetic expressions. The bit-wise operators may also be used with strings.
Bit-wise operators are useful for separating characters from an input string. When using the input
command for string input, the input variable holds 6 bytes of data. Each byte is eight bits, so a number
represented as 32 bits of integer and 16 bits of fraction. Each ASCII character is represented as one
byte (8 bits), therefore the input variable can hold a six character string. The first character of the
string will be placed in the top byte of the variable and the last character will be placed in the lowest
significant byte of the fraction. The characters can be individually separated by using bit-wise
operations as illustrated in the following example:
Instruction
#TEST
IN "ENTER",LEN{S6}
FLEN=@FRAC[LEN]
FLEN=$10000*FLEN
LEN1=(FLEN&$00FF)*$1000000
LEN2=(FLEN&$FF00)*$10000
LEN3=(LEN&$000000FF)*$1000000
LEN4=(LEN&$0000FF00)*$10000
LEN5=(LEN&$00FF0000)*$100
LEN6=(LEN&$FF000000)
MG LEN6 {S1}
MG LEN5 {S1}
MG LEN4 {S1}
MG LEN3 {S1}
MG LEN2 {S1}
MG LEN1 {S1}
EN
This program will accept a string input of up to 6 characters, parse each character, and then display
each character. Notice also that the values used for masking are represented in hexadecimal (as
denoted by the preceding '$'). For more information, see section Sending Messages.
DMC-1000
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com
The variable, COUNT, is equal to the current value plus 2.
Puts the position of X - 28.28 in RESULT. 40 * cosine of 45° is 28.28
TEMP is equal to 1 only if Input 1 and Input 2 are high

Bit-Wise Operators

Interpretation
Begin main program
Input character string up to 6 characters into variable 'LEN'
Define variable 'FLEN' as fractional part of variable 'LEN'
Shift FLEN by 32 bits (Convert fraction, FLEN, to integer)
Set 4
Set 3
Set 1
Set 1
Set 1
Set 1
Display 'LEN6' as string message of 1 char
Display 'LEN5' as string message of 1 char
Display 'LEN4' as string message of 1 char
Display 'LEN3' as string message of 1 char
Display 'LEN2' as string message of 1 char
Display 'LEN1' as string message of 1 char
th
st
byte of FLEN = 1
byte of variable LEN1
rd
st
byte of FLEN = 1
byte of variable of LEN2
st
th
byte of variable LEN3 = 4
byte of LEN
st
rd
byte of variable LEN4 = 3
byte of LEN
st
nd
byte of variable LEN5 = 2
byte of LEN
st
st
byte of variable LEN6 = 1
byte of LEN
Chapter 7 Application Programming • 101

Advertisement

Table of Contents
loading

Table of Contents