Overview of the Bits Package
Calling Sequence
Description
Examples
Bits:-command(arguments)
command(arguments)
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
Join
Split
String
Bit Operations, Setting, and Queries
GetBits
Settings
FirstNonzeroBit
Logic Operations
Not
And
Or
Xor
Nand
Nor
Iff
Implies
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.
with⁡Bits:
v1≔Join⁡map⁡op,`$`⁡0,1,32
v1≔12297829382473034410
3⁢v1+2−265
0
v2 := Not(v1,bits=64);
v2≔6148914691236517205
And(v1,v2);
Not(Or(v1,v2),bits=64);
String⁡v1
0101010101010101010101010101010101010101010101010101010101010101
String⁡v2
101010101010101010101010101010101010101010101010101010101010101
String⁡v2,bits=64
1010101010101010101010101010101010101010101010101010101010101010
Settings⁡defaultbits=64:
Settings⁡defaultbits=−1:
Not(0);
18446744073709551615
264−1
Or(-2,-4,bits=8);
254
Or(-2,-16,bits=8);
And(-1,144,bits=8);
144
Settings⁡negativeout=true:
−112
See Also
Download Help Document