PC(1)PC(1)
NAME
pc – programmer’s calculator
SYNOPSIS
DESCRIPTION
Expressions can use the C-like operators
The $ operator performs sign extension. n$x truncates x to n bits and sign extends. If n is omitted, it is inferred from the highest set bit (the result is always ≤ 0 in this case).
Variables can be defined using
Numbers can use the prefixes
Builtin functions
Display n in binary.
Display n in octal.
Display n in decimal.
Display n in hexadecimal.
Display n in base b (currently must be one of 0, 2, 8, 10, 16; 0 uses the defined output base).
Absolute value of n.
n rounded to the nearest multiple of m. Numbers exactly halfway between are rounded to the next even multiple.
n rounded down to the next multiple of m.
n rounded up to the next multiple of m.
n truncated to m bits.
n truncated to m bits, with the highest bit interpreted as a sign bit.
n truncated to m bits, with the order of bits reversed.
The minimum number of bits required to represent n as an unsigned number.
The minimum number of bits required to represent n as an signed number.
The number of bits set in n.
Truncate each of the ai arguments to ni bits and concatenate their binary representation.
The greatest common divisor of n and m.
The ceiling of the logarithm of a with respect to base b. b can be omitted, in which case it defaults to 2.
The inverse of n mod m.
A random number satisfying 0 ≤ rand(n) < n.
Control statements
Control statements are always evaluated with default input base 10.
If n ≠ 0, insert
Set the default input base to n (default 10). The input base can always be overriden by the base prefixes defined above.
Set the output base to n. If n = 0 (default), print each number in the base it was input in.
Use Euclidean division (default). a / b is rounded towards ±∞ (opposite sign as b). a % b is always non-negative.
Use truncating division (same as C). a / b is rounded towards zero. a % b can be negative.
Enable numbering bits (disable with 0). If the base is a power of two, print the number of the corresponding bit above each digit.
SOURCE
SEE ALSO
BUGS
With the input base set to 16, terms such as
Arbitrary bases should be supported, but are not supported by the