{{htmlmetatags>metatag-robots=()
metatag-title=(AND | ugBASIC User Manual)
metatag-keywords=(ugBASIC,Commodore 64,Commodore PLUS/4,ZX Spectrum)
metatag-description=(Manual page for AND)
metatag-media-og:image=(:ugbasic:logo-ugbasic-fb.png)
metatag-og:title=(AND | ugBASIC User Manual)
metatag-og:description=(Manual page for AND)
}}
====== ugBASIC User Manual ======
===== AND =====
===== SYNTAX =====
= x AND y
==== PURPOSE ====
Performs a logical conjunction on two expressions, as a bitwise conjunction. For comparisons managed
as a boolean result (''TRUE'' or ''FALSE''), result is ''TRUE'' if, and
only if, both expresions evaluate to ''TRUE''. The following table shows how result is determined:
'''TRUE AND TRUE = TRUE'''
'''TRUE AND FALSE = FALSE'''
'''FALSE AND TRUE = FALSE'''
'''FALSE AND FALSE = FALSE'''
Generally speaking, the ''AND'' operator performs a bitwise comparison of the bits of two numeric
expressions and sets the corresponding bit in result according to the previous table.
Note that ugBASIC uses the convention, very common in BASICs of the 1970s and 1980s,
of considering Boolean logic as implemented through the so-called "two's complement".
In other words, the value ''FALSE'' is associated with a number composed of
all ''0''s, in terms of bits. The value ''TRUE'' is, instead,
associated with a number composed of all ''1''s, again in terms of bits.
According to the 2's complement representation, a number composed of all ones is
always equivalent to the number ''-1'', regardless of how many bits the
number is composed of, while a number composed of all zeros is always equivalent to zero.
According to this convention, there is a coincidence between bitwise and logical
operations: in fact, a bitwise ''AND'', applied to all the bits of the number,
will be equivalent to the logical operation. Note tha the ''AND'' operator always evaluates
both expressions, which can include executing routine calls.
Because the logical and bitwise operators have lower precedence than other arithmetic and relational
operators, all bitwise operations must be enclosed in parentheses to ensure accurate results.
If the operands consist of a ''SIGNED BYTE'' expression and a numeric expression, converts the
''SIGNED BYTE'' expression to a numeric value (''-1'' for ''TRUE'' and 0 for ''FALSE'') and
performs a bitwise operation. So, the data type of the result is a numeric type appropriate
for the data types of both expressions.
==== EXAMPLE ====
IF x AND 1 THEN
PRINT "x is odd"
ELSE
PRINT "x is even"
ENDIF
==== ABBREVIATION ====
An
==== AVAILABLE ON ====
*
* Atari (400/800)
* Atari XL/XE
* Commodore 128 (MOS 8502)
* Commodore 128 (Zilog Z80)
* Commodore 64
* Commodore 64+REU
* TRS-80 Color Computer
* TRS-80 Color Computer 3
* ColecoVision
* Amstrad CPC 664
* Dragon 32
* Dragon 64
* Thomson MO5
* Thomson MO5
* Olivetti Prodest PC128
* Commodore PLUS/4
* SEGA SC-3000
* SEGA SG-1000
*
* VG-5000
* Commodore VIC-20
* ZX Spectrum 48
==== ANY PROBLEM? ====
If you have encountered a problem using this command, if you think there is a bug or the explanation is unclear, please [[https://github.com/spotlessmind1975/ugbasic/issues/new?title=ISSUE ON AND|open an issue]] for this keyword on GitHub. Thank you!===== POWERED BY =====
[[:ugbasic:user:index|{{ :ugbasic:user:logo-ugbasic.png?nolink&600 |}}]]