Operators
Assignment Operator =
The assignment operator, =, assigns a value to a variable.
In BCX, a literal decimal numeric value can be assigned to a variable, as in this example
DIM Number Number = 20200628 PRINT Number
Result:
20200628
In BCX, a literal hexadecimal numeric value can be assigned to a variable, as in this example
DIM Number Number = 0x1343CB4 PRINT Number
Result:
20200628
In BCX, a literal octal numeric value can be assigned to a variable, as in this example
DIM Number Number = %0115036264 PRINT Number
Result:
20200628
In BCX, a literal binary numeric value can be assigned to a variable, as in this example
$BCXVERSION "7.4.7 (2020/06/29)" DIM Number Number = 0b00000001001101000011110010110100 PRINT Number
Result:
20200628
Order of Operations
When several BCX operators occur in the same statement, they are executed in the following order:
Order of Operations 
Operator Symbol 
Operation  Direction of Evaluation 

1st  ()  Parentheses or function call  Left to right 
[]  Array element  
.  TYPE or UNION member  
>  Pointer reference to member  
++  Post increment variable++  
  Post decrement variable  
2nd  SIZEOF  Size of object in bytes  Right to left 
&  Address of  
*  Contents of  
+  Unary plus  
  Unary minus  
~  Bitwise complement ("ones complement")  
BNOT  Bitwise complement ("ones complement")  
++  Pre increment ++variable  
  Pre decrement variable  
3rd  (DataType)  Cast (Cstyle type conversion)  Right to left 
4th  *  Multiply  Left to right 
/  Divide  
%  Remainder  
5th  +  Add  Left to right 
  Subtract  
6th  <<  Bitwise left shift  Left to right 
>>  Bitwise right shift  
7th  <  Scalar less than  Left to right 
<=  Scalar less than or equal to  
>  Scalar greater than  
>=  Scalar greater than or equal to  
8th  =  Scalar equal  Left to right 
EQUALTO  Scalar equal  
<>  Scalar not equal  
><  Scalar not equal  
NOTEQUALTO  Scalar not equal  
9th  BAND  Bitwise conjunction on two binary integers  Left to right 
&  Bitwise conjunction on two binary integers  
10th  XOR  Exclusive logical disjunction on two expressions.  Left to right 
11th  BOR  Bitwise disjunction on two binary integers  Left to right 
  Bitwise disjunction on two binary integers  
12th  AND  Logical conjunction on two Boolean expressions  Left to right 
ANDALSO  Logical conjunction on two Boolean expressions  
&&  Logical conjunction on two Boolean expressions  
13th  OR  Logical disjunction on two Boolean expressions  Left to right 
ORELSE  Logical disjunction on two Boolean expressions  
  Logical disjunction on two Boolean expressions  
14th  =  Direct assignment  Right to left 
*=  Assignment by product  
/=  Assignment by quotient  
+=  Assignment by sum  
=  Assignment by difference  
<<=  Assignment by Bitwise left shift  
>>=  Assignment by Bitwise right shift  
&=  Assignment by Bitwise AND  
=  Assignment by Bitwise OR  
15th  ,  Sequential expression  Left to right 
β BCX does not support the following assignment operators
^= assignment by bitwise XOR %= assignment by remainder.
In BCX the ^ symbol as the exponentiation operator, while in the C language, the ^ symbol is used for the bitwise exclusive or (XOR) operator. The shortcut %= does not work because, in BCX the % symbol is used as the data type identifier appended to an INTEGER variable. To use either, inline C code must be used, for example,
! a^=2; ! a%=2;
If the operations are different and are of the same level, the leftmost one is executed first and the rightmost last.
The order of operations in the following example
DIM a% a% = 42 + 6 * 4 / 2  1 PRINT a%
is as follows:
1. 6 * 4 (= 24) 2. 24 / 2 (= 12) 3. 12 + 42 (= 54) 4. 54  1 (= 53)
The above example can be expressed unambiguously, with parentheses, as
DIM a% a% = (42 + ((6 * 4) / 2))  1 PRINT a%
Exponentiation ^ operator
Example 1:
DIM a, b b = 3 a = 10 ^ b ? a
Result:
0.001
Example 2:
DIM a# a# = 5 ^ 2 PRINT a# a# = 25 ^ 0.5 PRINT a#
Result:
25 5
Example 3:
DIM cum#[1000] DIM tcont, pd# tcont = 1 cum#[tcont] = 17 pd# = 2 PRINT (cum#[tcont] ^ (1 / ((tcont + 1) / pd#))  1) * 100 PRINT 7 ^ (MOD(13, 7)) PRINT (SIN(13)) ^ (SIN(13)) PRINT pd ^ (pd ^ 2) PRINT pd ^ pd PRINT 7 ^ (IMOD(3,2)) PRINT POW(2, POW(2, POW(2, 2))) PRINT 2 ^ (2 ^ (2 ^ (2))) PRINT pd ^ pd  pd ^ (LOG(pd))  (SIN(pd)) ^ 7
Result:
1600 117649 0.6946632571379008 16 4 7 65536 65536 1.869218636052765
BNOT operator
Syntax: RetVal% = BNOT Number Parameters:

Remarks:
BNOT is a bitwise inversion operator, commonly known as "One's Complement". BNOT inverts binary bits in a numeric expression to 0 if 1 and to 1 if 0. The BNOT operator uses this "truth table":
 Bit in Expression Bit in Result  1 0 0 1 
Example:
DIM int1%, int2% DIM BINstr1$, BINstr2$ int1% = 12345 BINstr1$ = LPAD$(BIN$(int1%),32, ASC("0")) PRINT BINstr1$ int2% = BNOT int1% BINstr2$ = BIN$(int2%) PRINT BINstr2$
Result:
00000000000000000011000000111001 11111111111111111100111111000110
BOR operator
Syntax: RetVal% = Number1 BOR Number2 Parameters:

Remarks:
The bitwise BOR operator compares corresponding bits in numericexpression1 and numericexpression2, then sets the corresponding bit in the result according to the following table:
 Bit in Expression1 Bit in Expression2 Bit in Result  1 1 1 1 0 1 0 1 1 0 0 0 
Example:
DIM a, b a = 0 b = a BOR 1 ? b b = a BOR 0 ? b
Result:
1 0
BAND operator
Syntax: RetVal% = Number1 BAND Number2 Parameters:

Remarks:
The BAND bitwise operator compares corresponding bits in two numeric expressions and sets the corresponding bit in the result to 1 if both bits are 1. The BAND operator uses this "truth table":
 Bit in Expression1 Bit in Expression2 Bit in Result  1 1 1 1 0 0 0 1 0 0 0 0 
Example:
DIM a, b a = 1 b = a BAND 1 ? b b = a BAND 0 ? b
Result:
1 0
Example:
The following program demonstrates the use of BAND to determine whether a number is even or odd.
DIM A% INPUT "Number ? "; A% IF A% BAND 1 THEN PRINT A%, " is odd" ELSE PRINT A%, " is even" END IF
XOR operator
Syntax: RetVal% = Number1 XOR Number2 Parameters:

Remarks:
The logical "exclusive or"(sometimes called the difference detector) operator compares corresponding bits in Number1 and Number2 then sets the corresponding bit in RetVal% according to the following table:
 Bit in Expression1 Bit in Expression2 Bit in Result  1 1 0 1 0 1 0 1 1 0 0 0 
Example 1:
DIM Counter%, LenStr1% DIM Str1$ Str1$ = "tI esreveR" LenStr1% = LEN(Str1$)  1 DO WHILE Counter% < LenStr1% Str1[Counter] = Str1[Counter] XOR Str1[LenStr1] Str1[LenStr1] = Str1[LenStr1] XOR Str1[Counter] Str1[Counter] = Str1[Counter] XOR Str1[LenStr1] LenStr1 Counter++ LOOP PRINT Str1$
Result:
Reverse It
Remarks:
The most rapid string reversal implementation is found in the BCX π REVERSE$ function.
REVERSE$ <<< This is a link to the reverse page.Example 2:
$COMMENT  FUNctions with bits! by Jeff Nope jeffnope@hotmail.com Feel free to use these, you just can't hold me responsible, and give credit where credits due :)  All BitNum's are zero based  a = BitClr(a, BitNum) Clears a particular bit in variable a (to a value of 0).  a = BitSet(a, BitNum) Sets a particular bit in variable a (to a value of 1).  b = BitTst(a, BitNum) Determines whether a given bit is set in a. function result b = TRUE if the specified bit is set (that is, has a value of 1) and b = FALSE if the bit is cleared (that is, has a value of 0).  a = BitTgl(a, BitNum) Toggles a particular bit in variable a  z$ = dec2bin$(a, length) Converts variable a into a string representing the binary value of a. The length variable is optional for formating, for example 8 gives a byte. This function is the opposite of BIN2DEC(z$) a BCX built in function.  $COMMENT DIM a, b, i DIM z$ z$ = "101001" ? "z$ = " & z$ ? "a = BIN2DEC (z$)" a = BIN2DEC (z$) 'BCX built in function ? "a =" & a ? ?"z$ = dec2bin$(a, 8) (with optional length):" z$ = dec2bin$(a, 8) 'the optional length of 8, will cause leading zero's here ? "z$ = " & z$ & "b" ? ?"z$ = dec2bin$(a) (without the optional length):" z$ = dec2bin$(a) ? "z$ = " & z$ & "b" ? ? "a = BitSet(a, 1)" a = BitSet(a, 1) 'set bit 1 in variable a z$ = dec2bin$(a, 8) 'the optional length of 8, will cause leading zero's here ? "a = " & a & " : " & z$ & "b" ? ? "a = BitClr(a, 1)" a = BitClr(a, 1) z$ = dec2bin$(a, 8) 'the optional length of 8, will cause leading zero's here ? "a = " & a & " : " & z$ & "b" ? ? "a = BitTgl(a, 1)" a = BitTgl(a, 1) 'make sure it can toggle a bit z$ = dec2bin$(a, 8) 'the optional length of 8, will cause leading zero's here ? "a = " & a & " : " & z$ & "b" ? ? "a = BitTgl(a, 1)" a = BitTgl(a,1) 'make sure it can toggle a bit back z$ = dec2bin$(a, 8) 'the optional length of 8, will cause leading zero's here ? "a = " & a & " : " & z$ & "b" ? ? "b = BitTst(a, i) loop:" FOR i = 7 TO 0 STEP 1 'loop for 8 bits starting at the MSB b = BitTst(a, i) 'Test the i'th bit in a ? b; 'print the bits one at a time NEXT END FUNCTION BitTst(a, BitNum) 'BitNum is zero based DIM tmp tmp = a BAND 1 << BitNum IF tmp > 0 THEN tmp = 1 FUNCTION = tmp END FUNCTION FUNCTION BitSet(a, BitNum) 'BitNum is zero based DIM tmp tmp = a BOR 1 << BitNum FUNCTION = tmp END FUNCTION FUNCTION BitClr(a, BitNum) 'BitNum is zero based DIM tmp tmp = a BAND ((1 << BitNum) XOR 0xFFFFFFFF) 'the XOR with all 1's causes all bits to toggle FUNCTION = tmp END FUNCTION FUNCTION BitTgl(a, BitNum) 'BitNum is zero based DIM tmp tmp = a XOR 1 << BitNum 'the XOR with 1 causes bit to toggle FUNCTION = tmp END FUNCTION FUNCTION dec2bin$ OPTIONAL (a, length = 0) 'optionally formated DIM i, tmp, t, T$ IF length = 0 THEN 'we don't know the length here tmp = a WHILE tmp > 0 tmp = tmp >> 1 length++ WEND END IF t = 1 FOR i = 1 TO length 'we know the length here tmp = a BAND t 'logical AND to test the bit IF tmp = 0 THEN T$ = "0" & T$ ELSE T$ = "1" & T$ END IF t = t << 1 NEXT FUNCTION = T$ END FUNCTION
Result:
z$ = 101001 a = BIN2DEC (z$) a = 41 z$ = dec2bin$(a,8) (with optional length): z$ = 00101001b z$ = dec2bin$(a) (without the optional length): z$ = 101001b a = BitSet(a,1) a = 43 : 00101011b a = BitClr(a,1) a = 41 : 00101001b a = BitTgl(a,1) a = 43 : 00101011b a = BitTgl(a,1) a = 41 : 00101001b b = BitTst(a,i) loop: 0 0 1 0 1 0 0 1
ANDALSO and ORELSE Operators
ANDALSO and ORELSE were added to the BCX lexicon for the convenience of users of other BASIC dialects which have these operators. The functionality of ANDALSO is equivalent to the C language && operator which will evaluate the second operand only if the first evaluates as TRUE (non zero). The functionality of ORELSE is equivalent to the C language  operator which will evaluate the second operand only if the first evaluates as FALSE (zero).
Example:
DIM AS BOOL bResult1, bResult2, bX1, bX2 DIM szBuf$ bX1 = TRUE bX2 = FALSE bResult1 = bX1 ANDALSO bX2 bResult2 = bX1 ORELSE bX2 PRINT "bX1 bX2 bX1 ANDALSO bX2 bX1 ORELSE bX2" sprintf(szBuf,"%3i %3i %2i %2i",bX1,bX2,bResult1, bResult2) PRINT szBuf bResult1 = bX1 AND bX2 bResult2 = bX1 OR bX2 PRINT "bX1 bX2 bX1 AND bX2 bX1 OR bX2" sprintf(szBuf,"%3i %3i %2i %2i",bX1,bX2,bResult1, bResult2) PRINT szBuf bResult1 = bX1 && bX2 bResult2 = bX1  bX2 PRINT "bX1 bX2 bX1 && bX2 bX1  bX2" sprintf(szBuf,"%3i %3i %2i %2i",bX1,bX2,bResult1, bResult2) PRINT szBuf PAUSE
Result:
bX1 bX2 bX1 ANDALSO bX2 bX1 ORELSE bX2 1 0 0 1 bX1 bX2 bX1 AND bX2 bX1 OR bX2 1 0 0 1 bX1 bX2 bX1 && bX2 bX1  bX2 1 0 0 1
Truth Table for Logical Operators
β When using the operators NOT, AND, OR, XOR, a space must be before and after the operator, like this,
IF (c > 64 AND c < 91) OR (c > 96 AND c < 123) THEN
Each operator returns results as indicated below. A "T" indicates a true value and an "F" indicates a false value. Operators are listed in order of operator precedence.
Values of Value Returned by Logical Operator X X X NOT AND OR XOR X Y X Y Y Y  T T F T T F T F F F T T F T T F T T F F T F F F
Bit Shift << and >> operators
Purpose: These operators shift the first parameter left (<<) or right (>>) by the number of places in the second parameter. Both parameters must be integers.
Shift Left << operator
Syntax:
RetVal% = IntNum% << NumPlaces%
Parameters:

Remarks: Vacated right bits are set to 0.
Shift Right >> operator
Syntax:
RetVal% = IntNum% >> NumPlaces%
Parameters:

Remarks: Vacated left bits are set to 0 if the integer type is unsigned. Otherwise, they are filled with copies of the sign bit.
Example:
DIM value% value% = 32768 << 1 'Shift left 1 place PRINT value% value% = 32768 >> 1 'Shift right 1 place PRINT value%
Result:
65536 16384
Relational Operators
Relational operators are used to compare two values. The result of the comparison is either "true", nonzero, or "false", zero. This result can then be used to make a decision regarding program flow. Although BCX treats any nonzero value as true, true is usually represented by 1. When arithmetic and relational operators are combined in one expression, the arithmetic operations are always done first.
Operator Relation Expression = Equality X = Y EQUALTO Equality X EQUALTO Y <> Inequality X <> Y NOTEQUALTO Inequality X NOTEQUALTO Y < Less than X < Y > Greater than X > Y <= Less than or equal to X <= Y >= Greater than or equal to X >= Y Note: The keyword IS can be used in place of the = equality relational operator. IS Equality X IS Y The LET keyword can precede statements containing the equality relational operator(=). LET A% = 6 * 6
In the following example BCX will give a different answer than most dialects of BASIC.
DIM RetVal%, A%, B%, C% RetVal% = 3 * ((A% >= B%) + (B% <= C%)) ? RetVal%
Result:
6
Using BCX, the example above returns an integer value of 6. Using QBASIC, the result is 6. The reason is because most BASIC dialects define TRUE as 1, but in the C language, TRUE is defined as 1. Each parenthetical evaluates to TRUE and in QBASIC, the statement reduces down to 3 * ( 1 + 1). In BCX, the statement reduces down to 3 * (1 + 1).
Example:
DIM c DIM d c = 42 d = 6 IF d < c THEN ? "It works!" IF d > c THEN ? "error" IF d <> c THEN ? "It works!" IF d = c THEN ? "error" IF d <= c THEN ? "It works!" IF d >= c THEN ? "error"
Result:
It works! It works! It works!
String Concatenation Operators + and &
A string expression consists of string constants, string variables, and other string expressions combined by string concatenation operators. The act of combining two strings is called concatenation.
In BCX, the plus + symbol or the ampersand & symbol may be used for concatenation.
For example, the following program fragment combines the string variables A$ and B$ to produce the value FILENAME:
DIM A$ DIM B$ A$ = "FILE" B$ = "NAME" PRINT A$ + B$ PRINT "NEW " & A$ & B$
Result:
FILENAME NEW FILENAME
Remarks:
β String concatenation will not work with strings containing an embedded ASCII NULL.
EndOfLine Continuation Operator _
The endofline continuation operator, _, the underscore, may be used to split a long line of code into multiple lines. The underscore is placed at the end of each segment of the split line except for the last segment. The underscore must be separated by a space from the last character in the line segment.
For example, this line of code
ShellExecute(0, "open", "http://www.w3.org", "", 0, 1)
could have comments added explaining the parameters and be segmented into this
ShellExecute(0, _ ' handle to parent window "open", _ ' pointer to string that specifies operation to perform "http://www.w3.org", _ ' pointer to filename string "", _ ' pointer to string that specifies executablefile parameters 0, _ ' pointer to string that specifies default folder 1) ' whether file is shown when opened
String Comparison Operators
String comparisons are made by taking corresponding characters from each string operand and comparing their ASCII codes. If the ASCII codes are the same for all the characters in both strings, the strings are equal. If the ASCII codes differ, the lower code number precedes the higher. If the end of one string is reached during string comparison, the shorter string is smaller if they are equal up to that point. Leading and trailing blanks are significant.
Strings can be compared using the following relational operators:
Operator Relation Expression = Equality X$ = Y$ <> Inequality X$ <> Y$ < Less than X$ < Y$ > Greater than X$ > Y$
β <= and >= cannot be used to compare case sensitive strings.
Example 1:
DIM S AS STRING DIM T AS STRING S="Test" T="Test" IF T$ = S$ THEN PRINT " S equals T" ELSE PRINT " S does not equal T" END IF
Result:
S equals T
Example 2:
IF "BCX" = "bcx" THEN PRINT "True" ELSE PRINT "False" IF "BCX" != "bc" THEN PRINT "True" ELSE PRINT "False" IF "BCX" =! "bc" THEN PRINT "True" ELSE PRINT "False" IF "BCX" NOT = "bc" THEN PRINT "True" ELSE PRINT "False" IF "BCX" <> "bc" THEN PRINT "True" ELSE PRINT "False" IF "BCX" > "bc" THEN PRINT "True" ELSE PRINT "False" IF "BCX" < "bc" THEN PRINT "True" ELSE PRINT "False"
Result:
False True True True True False True
String Relational Operator ??
The string relational operator ?? is used to perform an efficient, localeaware, caseinsensitive string comparison in IF...THEN and DO/WHILE/UNTIL/LOOP's.
Example 1:
DIM AS STRING szNames1,szNames2 szNames1 = "BCX" szNames2 = "bcx" IF szNames1$ ?? szNames2$ THEN ? "Strings Are Equal" ELSE ? "Strings Are Not Equal!" ENDIF PAUSE
Result:
Strings Are Equal
Example 2:
IF "BCX" ?? "bcx" THEN PRINT "True" ELSE PRINT "False" IF "BCX" >?? "bc" THEN PRINT "True" ELSE PRINT "False" IF "BCX" ??> "bc" THEN PRINT "True" ELSE PRINT "False" IF "BCX" <?? "bc" THEN PRINT "True" ELSE PRINT "False" IF "BCX" ??< "bc" THEN PRINT "True" ELSE PRINT "False" IF "BCX" <??> "bc" THEN PRINT "True" ELSE PRINT "False" IF "BCX" !?? "bc" THEN PRINT "True" ELSE PRINT "False" IF "BCX" ??! "bc" THEN PRINT "True" ELSE PRINT "False" IF "BCX" NOT ?? "bc" THEN PRINT "True" ELSE PRINT "False"
Result:
True True True False False True True True True
Example 2:
DIM A$, i i = 65 WHILE A$ !?? "AbCdEf" A$ = A$ + CHR$(i++) ? A$ WEND
Result:
A AB ABC ABCD ABCDE ABCDEF
Example 3:
DIM i, A$, B$ B$ = "AAAAA" DO UNTIL A$ > ?? B$ ' until A$ is greater than or equal to B$ A$ = A$ + "A" LOOP PRINT A$
Result:
AAAAAA
Remarks:
The raison d'Γͺtre for the ?? operator is to simplify code from this:
IF LCASE$(SomeString$) = "I like Cocoa Puffs" THEN ...to this
IF SomeString$ ?? "I like Cocoa Puffs" THEN ...
This is accomplished by the ?? operator instructing BCX to emit the unique bcx_stricmp function instead of strcmp.
As with the = sign, the <, >, <>, and NOT operators may also be used.
You may liberally use whitespace between the symbols: ? < > !.
Increment and Decrement Operators
PostIncrement ++ operator
Purpose: Appending ++ to a variable will increase the value of the variable by 1.
Syntax: variable++ Parameters:

Remarks: If a postincremented variable appears in an expression, the expression is evaluated using the current value of variable and then the variable is incremented by 1.
++ PreIncrement operator
Purpose: Prepending ++ to a variable will increase the value of the variable by 1.
Syntax: ++variable Parameters:

Remarks: If a preincremented variable appears in an expression, the variable is incremented by 1 and then the expression is evaluated.
Post Decrement  operator
Purpose: Appending  to a variable will decrease the value of the variable by 1.
Syntax: variable Parameters:

Remarks: If a postdecremented variable appears in an expression, the expression is evaluated using the current value of variable and then the variable is decremented by 1.
 Pre Decrement operator
Purpose: Prepending  to a variable will decrease the value of the variable by 1.
Syntax: variable Parameters:

Remarks: If a predecremented variable appears in an expression, the variable is decremented by 1 and then the expression is evaluated.
Example 1:
DIM AS INTEGER x DIM AS INTEGER y ' Increment operators ' Preincrement: x is incremented by 1, then y is assigned the value of x x = 1 y = ++x ' x is now 2, y is also 2 ? x ? y ' Postincrement: y is assigned the value of x, then x is incremented by 1 x = 1 y = x++ ' y is 1, x is now 2 ? x ? y ' Decrement operators ' Predecrement: x is decremented by 1, then y is assigned the value of x x = 1 y = x ' x is now 0, y is also 0 ? x ? y ' Postdecrement: y is assigned the value of x, then x is decremented by 1 x = 1 y = x ' y is 1, x is now 0 ? x ? y
Result:
2 2 2 1 0 0 0 1
Example 2:
DIM a a = 42 ? a++ 'post increment(print a, 42, then a = a + 1) ? a 'print a, 43 ? ++a 'pre increment(a = a + 1, then print a, 44) ? a 'print a, 44 ? a 'post decrement(print a, 44, then a = a  1) ? a 'print a, 43 ? a 'pre decrement (a = a  1, then print a, 42) ? a 'print a, 42
Result:
42 43 44 44 44 43 42 42
Assignment Operators
Plus equals += operator
Purpose: A shorthand form of variable = variable + numericexpression.
Syntax: variable += numericexpression Parameters:

Minus equals = operator
Purpose: A shorthand form of variable = variable  numericexpression.
Syntax: variable = numericexpression Parameters:

Multiplied by equals *= operator
Purpose: A shorthand form of variable = variable * numericexpression.
Syntax: variable *= numericexpression Parameters:

Divided by equals /= operator
Purpose: A shorthand form of variable = variable / numericexpression.
Syntax: variable /= numericexpression Parameters:

Example:
DIM a a = 42 a += 2 'same as a = a + 2 ? a a = 2 'same as a = a  2 ? a a *= 2 'same as a = a * 2 ? a a /= 2 'same as a = a / 2 ? a
Result:
44 42 84 42