Bits - Maple Programming Help

Home : Support : Online Help : Programming : Bits : Bits/And

Bits

 And
 compute bit-wise and of the inputs

 Calling Sequence And(num1, num2) And(num1, num2, options)

Parameters

 num1 - an integer num2 - an integer options - optional arguments

Description

 • The And command computes the bit-wise logical and of the inputs returning in terms of a number. All bits that are set in both inputs will be set in the output.
 • And takes one optional argument, bits=number that specifies the number of bits to be considered in the input. All bits past the specified number are truncated.
 • Use with negative inputs requires that bits be set, either as an argument to And or globally via Settings. If both inputs are positive, no truncation need occur, so bits is computed as the largest most significant bit between the two inputs.

Examples

 > $\mathrm{with}\left(\mathrm{Bits}\right):$
 > $\mathrm{num1}≔\mathrm{Join}\left(\left[1,1,0,0,0,1,0,1,0,1,1,0,1,1,1\right]\right)$
 ${\mathrm{num1}}{≔}{30371}$ (1)
 > $\mathrm{num2}≔\mathrm{Join}\left(\left[0,1,1,0,0,1,0,0,1,0,0,0,1,0,1\right]\right)$
 ${\mathrm{num2}}{≔}{20774}$ (2)

The following number represents the And of num1,num2

 > $\mathrm{num3}≔\mathrm{Join}\left(\left[0,1,0,0,0,1,0,0,0,0,0,0,1,0,1\right]\right)$
 ${\mathrm{num3}}{≔}{20514}$ (3)

Compare:

 > num3,And(num1,num2);
 ${20514}{,}{20514}$ (4)

Negative inputs and outputs

 > $\mathrm{Settings}\left(\mathrm{defaultbits}=8,\mathrm{negativeout}=\mathrm{true}\right):$
 > And(-1,12);
 ${12}$ (5)
 > And(-1,-128);
 ${-128}$ (6)