Overview of the Bits Package - Maple Programming 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[\left[0,1\right]\$32\right]\right)\right)$
 ${\mathrm{v1}}{≔}{12297829382473034410}$ (1)
 > $3\mathrm{v1}+2-{2}^{65}$
 ${0}$ (2)
 > $\mathrm{v2}≔\mathrm{Not}\left(\mathrm{v1},\mathrm{bits}=64\right)$
 ${\mathrm{v2}}{≔}{6148914691236517205}$ (3)
 > $\mathrm{And}\left(\mathrm{v1},\mathrm{v2}\right)$
 ${0}$ (4)
 > $\mathrm{Not}\left(\mathrm{Or}\left(\mathrm{v1},\mathrm{v2}\right),\mathrm{bits}=64\right)$
 ${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):$
 > $\mathrm{Not}\left(0\right)$
 ${0}$ (10)
 > $\mathrm{Settings}\left(\mathrm{defaultbits}=64\right):$
 > $\mathrm{Not}\left(0\right)$
 ${18446744073709551615}$ (11)
 > ${2}^{64}-1$
 ${18446744073709551615}$ (12)
 > $\mathrm{Settings}\left(\mathrm{defaultbits}=-1\right):$
 > $\mathrm{Or}\left(-2,-4,\mathrm{bits}=8\right)$
 ${254}$ (13)
 > $\mathrm{Or}\left(-2,-16,\mathrm{bits}=8\right)$
 ${254}$ (14)
 > $\mathrm{And}\left(-1,144,\mathrm{bits}=8\right)$
 ${144}$ (15)
 > $\mathrm{Settings}\left(\mathrm{negativeout}=\mathrm{true}\right):$
 > $\mathrm{And}\left(-1,144,\mathrm{bits}=8\right)$
 ${-}{112}$ (16)