beetlebug▾
/

tcl::mathop bitwise

The commands of the operators of bits: shifts, and, or, exclusive or, and not.

tcl::mathop::<< INTEGER SHIFT
tcl::mathop::>> INTEGER SHIFT
tcl::mathop::& ?INTEGER ...?
tcl::mathop::| ?INTEGER ...?
tcl::mathop::^ ?INTEGER ...?
tcl::mathop::~ INTEGER

Description

Each command works on integers of any size, as numbers in two's complement with an endless row of sign bits. A float is an error.

A negative SHIFT is an error.

Arguments

ArgumentTypeDefaultDescription
INTEGERintegerrequiredAn integer of any size.
SHIFTintegerrequiredThe count of bits to shift, 0 or more.

Returns

An integer.

Examples

% tcl::mathop::<< 1 3
8

% tcl::mathop::<< 1 64
18446744073709551616

% tcl::mathop::>> -8 1
-4

% tcl::mathop::>> 1 100
0

% tcl::mathop::& 12 10
8

% tcl::mathop::&
-1

% tcl::mathop::| 1 2 4
7

% tcl::mathop::^ 5 3
6

% tcl::mathop::~ 5
-6

Errors

% tcl::mathop::<< 1 -1
negative shift argument
-errorcode NONE

% tcl::mathop::<< 1
wrong # args: should be "tcl::mathop::<< integer shift"
-errorcode TCL WRONGARGS

% tcl::mathop::~ 1 2
wrong # args: should be "tcl::mathop::~ integer"
-errorcode TCL WRONGARGS

# Tcl 9.1 only
% tcl::mathop::~ 1.5
cannot use floating-point value "1.5" as operand of "~"
-errorcode ARITH DOMAIN {floating-point value}

# Tcl 8.6 only
% tcl::mathop::~ 1.5
can't use floating-point value as operand of "~"
-errorcode ARITH DOMAIN {floating-point value}

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also