Calcolo

AA contatori calcolo

Nel riquadro Calculations, è possibile aggiungere una o più linee.

I comandi possono essere rappresentati dal nome di una Variabile, dal segno = (uguale), > (maggiore),< (minore),<> ( compreso), != (non uguale a), e altri, rappresentati nella tabella seguente.

(, )                                 - Parentesi

=, <> !=                       - uguale a, compreso, non uguale a.

+, -, *, /, %                    - Addzione, Sottrazione, Moltiplicazione, Divisione & Modulo.

<, <=, >, >=                  - Minore di, Minore di o uguale a, Maggiore di, Maggiore di o uguale a.

>>, <<                          - Sposta a sinistra, Sposta a destra

~, &, |, ^                       - Operazione bit a bit: Not, AND, OR, OR esclusivo.

NOT,AND,OR,XOR     - Operazione bit a bit: Not, AND, OR, OR esclusivo.

&&, ||, !                         - Operatori logici:  AND, OR, NOT

 

I valori numerici possono essere espressi in decimale, esadecimale (HEX) preceduto da 0x, in Binario , preceduto da 0b.

Esempi:

assumendo che le variabili siano state già definite, tutte le espressioni che seguono sono valide.

DELAY = DELAY + 1

DELAY = (MYVAR + 3) * 3

NEXTBIT = LASTBIT >> 2 & MASK

 AANDB = PORT_A AND PORT_B

 INVX = NOT X

Funzioni matematiche

float = fadd(float, float)

Add two floating point numbers together

float = fsub(float, float)

Subtract two floating point numbers

float = fmul(float, float)

Multiply two floating point numbers

float = fdiv(float, float)

Divide two floating point numbers

float = fmod(float, float)

MOD function for floating point numbers

byte = isinf(float)

Checks to see if the floating point number is infinite

byte = isnan(float)

Checks to see if the floating point is not a number

byte = float_eq(float, float)

Compares two floating point numbers to see if they are equal

byte = float_ge(float, float)

Compares two floating point numbers to see if they are greater then or equal   

byte = float_gt(float, float)

Compares two floating point numbers to see if they are greater then

byte = float_le(float, float)

Compares two floating point numbers to see if they are less then or equal

byte = float_lt(float, float)

Compares two floating point numbers to see if they are less then

int = random()

Generates a random number 0x0000 <=> 0xFFFF

fabs( x ), floor( x ), ceil( x )

Absolute value, floor and ceiling functions

fmod( x , y )

Floating point modulus (remainder of x divided by y)

sqrt( x ), cbrt( x )

Square and cube roots

log( x ), log10( x )

Logarithms (base e and base 10)

exp( x ), pow( x , y )

Exponential and power functions (x to the power of y)

sin( x ), cos( x ), tan( x )

Trigonometric functions

asin( x ), acos( x ), atan( x )

Inverse trigonometric functions

atan2( y , x )

Four-quadrant inverse tangent

sinh( x ), cosh( x ), tanh( x )

Hyperbolic functions

isnan( x ), isinf( x )

Tests for not-a-number and infinity

round( x )

Decimal rounding (x rounded to the nearest integer)

fround( x , y )

Floating point rounding (x rounded to y decimal places)

asinh( x ), acosh( x ), atanh( x )

Inverse hyperbolic functions

fact( x )

Factorial

Stringhe

AA contatori stringhe

Assegnazione di una stringa

Per assegnare un valore ad una Stringa è sufficiente utilizzare il simbolo=”.

esempi:

Str1 = “Hello”

Str2 = “ world”

Le stringhe possono essere trattate come un “byte arrays”, per poter manipolarei bytes individuali.

per una stringadi dati, per poter essere utilizzati con un altra stringa di dati, deve terminare co uno 0 (zero ) o un dato nullo.

Str1[0] = 'H'

Str1[1] = 'e'

Str1[2] = 'l'

Str1[3] = 'l'

Str1[4] = 'o'

Str1[5] = ' '

Str1[6] = 0

Assegnando ad una stringa “costante” una “variabile” , sarà automaticamente aggiunto un “null byte” alla fine della stringa.

Str1 =”hello”

le stringhe possono essere usate con il carattere “escape” :

\n (nuova linea), \r (ritorno carrello), \t ( tab), \xXX (valore byte in esadecimale), \\ carattere “backslash.

Str1 = “Hello\n\rworld”

stringhe concatenate

+

Concatenates the two string together in the order presented from left to right.

If the resulting string is longer than the array size of the receiving string then any extra characters are lost.


Str1 = "Hello "

Str2 = "World"

TestStr = Str1 + Str2


TestStr is now "Hello World"

 

Multiple concatenations are best done like this to avoid using excess memory. Note that each line contains only two values to be added together.

TestStr = "Multiple " + Str1

TestStr = TestStr + Str2


TestStr is now "Multiple Hello World"


NOTE: Due to a limitation in generated code the result of multiple concatenations in one operation is limited to 20 characters. So the result of Str1 + Str2 + Str3 should not exceed 20 characters.

Converting a numeric value/variable to a string

ToString$(value)

Changes the numeric value to a String.


TestStr = ToStr$(1234)


TestStr is now "1234"

 

Converting a string to upper case

ToUpper$(string)

Changes all letters to upper case.


TestStr = ToUpper$(Str1)


TestStr is now "HELLO "

 

Converting a string to lower case

ToLower$(string)

Changes all letters to lower case.


TestStr = ToLower$(Str1)


TestStr is now "hello "

 

Finding the length of a string

Length$(string)

Retrieves the length of the string.

This is not the Array size, but the number of characters in the array before a Null character is encountered.


RetVal = Length$(Str1)


RetVal is now 6


Note: Str1 array size is 20, but has a String of only 6 characters currently assigned to it hence the return value of 6.

 

String subset - characters from the start of the string

Left$(string, size) Retrieves a substring from the string of size characters starting from the leftmost character.

If the length of the string used to store the result is less than size of the substring returned then any extra characters are lost.


TestStr = Left$(Str1, 3)


TestStr is now "Hel"

 

String subset - characters from the end of the string

Right$(string, size)

Retrieves a substring from the string of size characters starting from the rightmost character.

i.e. a size of 4 retrieves the 4 rightmost characters.

If the length of the string used to store the result is less than size of the substring returned then any extra characters are lost.


TestStr = Right$(Str1, 3)


TestStr is now "lo "

 

 

String subset - characters from an arbitrary position in the string

Mid$(string, start, size)

Retrieves a substring from the string starting at position start of size characters. The first character of the string is at position zero.

If the length of the string used to store the result is less than size of the substring returned then any extra characters are lost.


TestStr = Mid$(Str1, 2, 3)


TestStr is now "llo"

 

 

String comparisons

Compare$(string1, string2, compare_type)

Compares the two strings, parameters 1 and 2, and returns a BYTE value corresponding to the following results:


0 = strings are identical

1 = string1>string2

255 = string2>string1


The 3rd parameter, compare_type, determines whether or not the check is case sensitive. values for compare_type are:

0 = case sensitive

1 = case insensitive.

Examples


Str1 = "ABC"

Str2 = "abc"


RetVal = Compare$(Str1, Str2, 0)


RetVal is now 255 as Str2 is later in the ASCII sequence.


RetVal = Compare$(Str1, Str2, 1)


RetVal is now 0 as when case insensitive the two strings are identical.


Str2 = Str1

RetVal = Compare$(Str1, Str2, 0)


RetVal is now 0 as both strings are identical.


String Compare Example

 

Converting a floating point value/variable to a string

FloatToString$( float )

Converts a floating point number into a string.


float = Floating point number to convert.

string = String variable to hold the conversion data.


string = FloatToString( float )

 

Converting a numeric value/variable to a hex string

NumberToHex$( number )

Converts a byte or int number into a hexadecimal string.


number = byte or integer number to convert.

string = String variable to hold the conversion data.


string = FloatToString( INT )

 

Converting a string to a numeric value/variable

StringToInt$(string)

Converts a string of numeric ASCII data into an integer numeric data value.


string = String variable containing numeric ASCII data.

returns numeric data from the string in decimal form.


number = StringToInt$( string )

 

Converting a string into a floating point value/variable

StringToFloat$( string )

Converts a string of numeric ASCII data into a floating point variable.


string = String variable containing numeric ASCII data.

returns numeric data from the string in floating point form.


float = StringToFloat$( string )

Se la vostra preparazione è a questo livello , è meglio in inglese; sul sito della matrix multimedia trovate anche gli esempi.

Riccardo Monti