Bits - Maple Help

Overview of the Bits Package

 Calling Sequence Bits:-command(arguments) command(arguments)

Description

 • The Bits package provides the ability to easily and efficiently perform bit-wise operations in Maple.
 • The underlying datatype for bit-wise operations is the integer, just as it is in C. Unlike C, however, bit-wise operations are not limited to hardware-sized integers (32 or 64 bits), but apply to integers of arbitrary length.
 • All operations are externally coded to provide greater efficiency.
 • The commands in the Bits package naturally split into several categories:

Import, Export, and Display

Bit Operations, Setting, and Queries

Logic Operations

 • For several of the commands you must specify how many bits they are actually dealing with (as leading zero bits are not respected by the integer datatype). For any commands in this category, the optional argument bits=n should be provided.
 Alternatively, you can use Settings to specify the default working bit count. Then, any commands that take the bits argument, when it is not specified, will use this value.
 • The option of working with signed integers generally requires that bits be set, and negative outputs (not the default) can also be requested using Settings. Note that by default, the Bits package uses 2s complement notation, so -1 = 11111... to however many bits are currently set.
 • Each function in the Bits package can be accessed by using either the long form or the short form of the function name in the command calling sequence.

Examples

 > $\mathrm{with}\left(\mathrm{Bits}\right):$
 > $\mathrm{v1}≔\mathrm{Join}\left(\mathrm{map}\left(\mathrm{op},\left[\mathrm{}\left(\left[0,1\right],32\right)\right]\right)\right)$
 ${\mathrm{v1}}{≔}{12297829382473034410}$ (1)
 > $3\mathrm{v1}+2-{2}^{65}$
 ${0}$ (2)
 > v2 := Not(v1,bits=64);
 ${\mathrm{v2}}{≔}{6148914691236517205}$ (3)
 > And(v1,v2);
 ${0}$ (4)
 > Not(Or(v1,v2),bits=64);
 ${0}$ (5)
 > $\mathrm{String}\left(\mathrm{v1}\right)$
 ${"0101010101010101010101010101010101010101010101010101010101010101"}$ (6)
 > $\mathrm{String}\left(\mathrm{v2}\right)$
 ${"101010101010101010101010101010101010101010101010101010101010101"}$ (7)
 > $\mathrm{String}\left(\mathrm{v2},\mathrm{bits}=64\right)$
 ${"1010101010101010101010101010101010101010101010101010101010101010"}$ (8)
 > $\mathrm{Settings}\left(\mathrm{defaultbits}=64\right):$
 > $\mathrm{String}\left(\mathrm{v2}\right)$
 ${"1010101010101010101010101010101010101010101010101010101010101010"}$ (9)
 > $\mathrm{Settings}\left(\mathrm{defaultbits}=-1\right):$
 > Not(0);
 ${0}$ (10)
 > $\mathrm{Settings}\left(\mathrm{defaultbits}=64\right):$
 > Not(0);
 ${18446744073709551615}$ (11)
 > ${2}^{64}-1$
 ${18446744073709551615}$ (12)
 > $\mathrm{Settings}\left(\mathrm{defaultbits}=-1\right):$
 > Or(-2,-4,bits=8);
 ${254}$ (13)
 > Or(-2,-16,bits=8);
 ${254}$ (14)
 > And(-1,144,bits=8);
 ${144}$ (15)
 > $\mathrm{Settings}\left(\mathrm{negativeout}=\mathrm{true}\right):$
 > And(-1,144,bits=8);
 ${-112}$ (16)