Imp and Imp8 Functions

Purpose

Used to perform a logical implication on two expressions.

Syntax

int = i Imp j( operator)
int = Imp(i, j [,m,…])( function)

int64 = i Imp8 j( operator)
int64 = Imp8(i, j [,m,…])( function)

i, j, m:integer expression

Description

i Imp j combines the expressions i and j based on their order. The result is equivalent to a logical sequence. This means that something is false only when a true statement is followed by a false one. For expressions i and j this applies to their binary representation, i.e. the resulting bit will be 0 only when the corresponding bit in the first argument (i) is 1 and in the second argument (j) is 0.

Bit 1 Bit 2 Result
0 0 1
0 1 1
1 0 0
1 1 1

Imp8 should be used for 64-bit integers.

Example

OpenW # 1

Print 3 Imp 10 // Prints -2

3 Imp 10 returns -2. To understand this all 32 bits must be examined:

Bin$(3,32) = 00000000000000000000000000000011

Bin$(10,32) = 00000000000000000000000000001010

Bin$(3 Imp 10),32) = 11111111111111111111111111111110

The result of 3 Imp 10 is therefore -2.

Remarks

Imp is the only bit-wise operator for which the order of the arguments is important. This is because the result will produce a 0 only when, at the same position, a "true" (1) in the first argument is followed by a "false" (0) in the second argument.

This is why Imp(3,10) returns the value -2 (see above), but 10 Imp 3 returns -9:

Bin$(10,32) = 00000000000000000000000000001010

Bin$(3,32) = 00000000000000000000000000000011

Bin$((10 Imp 3),32)= 11111111111111111111111111110111

10 Imp 3 = -9

See Also

And ,Or, Xor, Imp, Eqv, %&, |, ~, Operator Hierarchy

{Created by Sjouke Hamstra; Last updated: 10/10/2014 by James Gaite}