Syntax
Description
C = bitcmp(A,n)
returns the bit-wise complement of A
as an n
-bit floating-point integer (flint).
Example
With eight-bit arithmetic, the ones' complement of 01100011 (99, decimal) is 10011100 (156, decimal).
bitgetSyntax
Description
C = bitget(A,
returns the value of the bit at position bit
) bit
in A
. Operand A
must be a nonnegative integer, and bit
must be a number between 1 and the number of bits in the floating-point integer (flint) representation of A
(52 for IEEE flints). To ensure the operand is an integer, use the ceil
, fix
, floor
, and round
functions.
Example
The dec2bin
function converts decimal numbers to binary. However, you can also use the bitget
function to show the binary representation of a decimal number. Just test successive bits from most to least significant:
Maximum floating-point integer
Syntax
Description
bitmax
returns the maximum unsigned floating-point integer for your computer. It is the value when all bits are set, namely the value bitor
Syntax
Description
C = bitor(A,B)
returns the bit-wise OR of two nonnegative integer arguments A
and B
. To ensure the operands are integers, use the ceil
, fix
, floor
, and round
functions.
Examples
The five-bit binary representations of the integers 13 and 27 are 01101 and 11011, respectively. Performing a bit-wise OR on these numbers yields 11111, or 31.
bitsetSyntax
Description
C = bitset(A,
sets bit position bit
) bit
in A
to 1 (on). A
must be a nonnegative integer and bit
must be a number between 1 and the number of bits in the floating-point integer (flint) representation of A
(52 for IEEE flints). To ensure the operand is an integer, use the ceil
, fix
, floor
, and round
functions.
C = bitset(A,
sets the bit at position bit
,v) bit
to the value v
, which must be either 0 or 1.
Examples
Setting the fifth bit in the five-bit binary representation of the integer 9 (01001) yields 11001, or 25.
bitshiftSyntax
Description
returns the value of C = bitshift(A,k,n)
A
shifted by k
bits. If k>0
, this is same as a multiplication by 2
k
(left shift). If k<0
, this is the same as a division by 2
k (right shift). An equivalent computation for this function isC = fix(A*2^k)
.
If the shift causes C to overflow n
bits, the overflowing bits are dropped. A
must contain nonnegative integers between 0
and BITMAX
, which you can ensure by using the ceil
, fix
, floor
, and round
functions.
C = bitshift(A,k)
uses the default value of n = 53
.
Examples
Shifting 1100 (12, decimal) to the left two bits yields 110000 (48, decimal).
bitxorSyntax
Description
C = bitxor(A,B)
returns the bit-wise XOR of the two arguments A
and B
. Both A
and B
must be integers. You can ensure this by using the ceil
, fix
, floor
, and round
functions.
Examples
The five-bit binary representations of the integers 13 and 27 are 01101 and 11011, respectively. Performing a bit-wise XOR on these numbers yields 10110, or 22.
No comments:
Post a Comment