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

Online Help

All Products    Maple    MapleSim


Bits

  

GetBits

  

extract specified bits from a number

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

GetBits(number, locns)

GetBits(number, locns, options)

Parameters

number

-

an integer

locns

-

a single or sequence of locations or ranges

options

-

optional arguments

Description

• 

The GetBits command extracts the specified bits from a number. The locns argument can be a sequence of bit locations or bit location ranges, including negative ranges and negative offsets. Note that all bit locations are given with 0 as the location of the least significant bit. For example, -1..0 can be used to extract the bits in a number in reverse order.

• 

The optional arguments for GetBits are as follows:

output=form: where form can be sequence (the default), or number. When form is specified as sequence, the output will be in the form of a sequence of 0's and 1's corresponding to the specified bit locations. When form is specified as number, the bit sequence will be used to construct a number, where the first bit in locns will be the least significant bit in the output number.

bits=count: specifies the number of bits in the input number. Any bit references that exceed this value will have a value of zero. Any negative bit references that go past the least significant bit will return an error. The default bits value can be set via Settings.

Examples

withBits:

numJoin1,1,0,0,0,1,0,1,0,1,1,0,1,1,1

num30371

(1)

Get least significant bit.

GetBitsnum,0

1

(2)

Get most significant bit. (This will be 1 if bits is not specified.)

GetBitsnum,1

1

(3)

Get most significant bit assuming input is 16 bits

GetBitsnum,1,bits=16

0

(4)

Extract all bits - this is the same as Split

GetBitsnum,0..1

1,1,0,0,0,1,0,1,0,1,1,0,1,1,1

(5)

Splitnum

1,1,0,0,0,1,0,1,0,1,1,0,1,1,1

(6)

Reverse order of the bits as a 16 bit number

GetBitsnum,1..0,bits=16

0,1,1,1,0,1,1,0,1,0,1,0,0,0,1,1

(7)

Reverse order as a 16 bit number with number output is equivalent to extracting in reverse above followed by join

GetBitsnum,1..0,output=number,bits=16

50542

(8)

JoinGetBitsnum,1..0,bits=16

50542

(9)

Exchange first 8 bits and last 8 bits in a 16 bit number

num2GetBitsnum,8..15,0..7,output=number

num241846

(10)

Check:

convertnum,hex

76A3

(11)

convertnum2,hex

A376

(12)

See Also

Bits

convert/hex

Join

Settings

Split