141
CLEM Language Reference
Function Result Description
integer_bitcount(INT) Integer
Counts the number of 1 or 0 bits in the
two’s-complement representation of INT. If
INT is non-negative, Nis the number of 1 bits. If
INT is negative, it is the number of 0 bits. Owing to
the sign extension, there are an innite number of 0
bits in a non-negative integer or 1 bits in a negative
integer. It is always the case that integer_bitcount(INT)
=integer_bi tcount(-(INT+1)).
integer_leastbit(INT) Integer
Returns the bit position Nof the least-signicant bit
set in the integer INT.Nis the highest power of 2 by
which INT divides exactly.
integer_length(INT) Integer
Returnsthe length in bits of INT as atwo’s-complement
integer. That is, Nis the smallest integer such that INT
<(1 << N) if INT >= 0 INT >= (–1 << N) if INT < 0. If
INT isn on-negative, then the representation of INT as
an unsigned integer requires a eld of at least Nbits.
Alternatively,a minimum of N+1 bits is required to
represent INT asa signed integer, regardless of its sign.
testbit(INT,N) Boolean
Teststhe bit at position Nin the integer INT and returns
thestate o f bit Nas a Boolean value, which is true for 1
and false for 0.
Random Functions

The following functions are used to randomly select items or randomly generate numbers.

Function Result Description
oneof(LIST) Any
Returns a randomly chosen element of LIST. List items should
been tered as [ITEM1,ITEM2,...,ITEM_N]. Note that a list of eld
names can also be specied. For more information, see the
topicSu mmarizing Multiple Fields in Chapter 7 on p. 115.
random(NUM) Number
Returnsa uniformly di stributed random number of the same type
(INT or REAL), starting from 1 to NUM. If you use an integer,
then only integers are returned. If you use a real (decimal)
number, then real numbers are returned (decimal precision
determined by the stream options). The largest random number
returned by the function could equal NUM.
random0(NUM) Number
Thishas th es ame properties as random(NUM), but starting from
0. The largest random number returned by the function will
never equal X.
String Functions

In CLEM, you can perform the following operations with strings:

Compare strings
Create strings
Access characters