Bits - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Overview of the Bits Package

 

Calling Sequence

Description

Examples

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

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.

Examples

withBits:

v1Joinmapop,`$`0,1,32

v112297829382473034410

(1)

3v1+2265

0

(2)

v2 := Not(v1,bits=64);

v26148914691236517205

(3)

And(v1,v2);

0

(4)

Not(Or(v1,v2),bits=64);

0

(5)

Stringv1

0101010101010101010101010101010101010101010101010101010101010101

(6)

Stringv2

101010101010101010101010101010101010101010101010101010101010101

(7)

Stringv2,bits=64

1010101010101010101010101010101010101010101010101010101010101010

(8)

Settingsdefaultbits=64:

Stringv2

1010101010101010101010101010101010101010101010101010101010101010

(9)

Settingsdefaultbits=1:

Not(0);

0

(10)

Settingsdefaultbits=64:

Not(0);

18446744073709551615

(11)

2641

18446744073709551615

(12)

Settingsdefaultbits=1:

Or(-2,-4,bits=8);

254

(13)

Or(-2,-16,bits=8);

254

(14)

And(-1,144,bits=8);

144

(15)

Settingsnegativeout=true:

And(-1,144,bits=8);

−112

(16)

See Also

And

FirstNonzeroBit

GetBits

Iff

Implies

Join

Nand

Nor

Not

Or

Settings

Split

String

Xor