Here is how to use bits() functions.
Description:
Convert a number represented by a certain number system to a decimal number.
Syntax:
bits(xi,…)
Note:
The function converts a number of a certain number system to a decimal integer according to a specific rule. Parameter xi represents the value in the ith position of the number counted from right to left. When no option is present the function converts a binary number to a decimal number.
When there is only one parameter xi and xi is a sequence, write the parameter in the form of x1 , x2 ,…xi.
If there is only a single xi and it is a string, split it into a sequence of single characters first, and then perform the conversion.
number system
Parameter:
xi |
An integer/string. |
Option:
@h |
Convert xi to integer decimal number according to the rules of hexadecimal number system if it is the string. |
@d |
First convert xi to an integer if it is the string and then perform the operation according to rules of decimal number system. |
@b |
Convert to 0 if parameter xi is false and to 1 if the parameter is true, and then convert them to a decimal number according to the rules of binary system. |
@s |
Should work with other options to return the string forming the number of the corresponding number system. |
@n |
Convert to a long integer. |
@r |
Put lower bits before higher bits. |
Return value:
Numeric value/string
Example:
Convert from binary to decimal:
|
A |
|
1 |
=bits(1,0,1,1) |
11. As no options work, covert binary to decimal. |
2 |
=bits([1,0,1,1]) |
11. As the one parameter is a sequence, take members of the sequence as parameter values; in this case the operation is equivalent to bits(1,0,1,1). |
3 |
=bits("1","0","1","1") |
11. As the parameters are strings, first convert them to an integer and to decimal according to rules of binary system. |
4 |
=bits("1011") |
11. As the one parameter is a string, split it into a sequence of single characters; in this case the operation is equivalent to bits([1,0,1,1]). |
Convert hexadecimal to decimal:
|
A |
|
1 |
=bits@h("A",1,1,5) |
@h option works to convert hexadecimal number A115 to decimal and the result is 41237. |
With @d option:
|
A |
|
1 |
=bits@d("1","0","1","5") |
1015. As parameters are strings, first convert them to an integer and then to decimal. |
With @b option:
|
A |
|
1 |
=bits@b(true,false,true) |
5. The operation convert binary number 101 to decimal. |
Put lower bits before higher bits:
|
A |
|
1 |
=bits@r(0XBB0D8196) |
3138224534 |
Convert to long integer:
|
A |
|
1 |
=67546523567 |
|
2 |
=bits@n(67546523567) |
Return a long type: |
With @s option:
|
A |
|
1 |
=bits@sd(1212) |
1212. Get the decimal string forming 1212. |
2 |
=bits@sh(1212) |
4bc. Get the hexadecimal string forming 1212. |
Description:
Convert a sequence of bit values to a sequence of long numeric values.
Syntax:
A.bits()
Note:
The function converts a sequence of binary bits A to a sequence of long numeric values, during which every 64 members is transformed to one long numeric member.
Parameter:
A |
A sequence of binary bits. |
Option:
@b |
When A consists of Boolean members, convert to 1 for true and to 0 for false. |
Return value:
A sequence of long numeric values
Example:
|
A |
|
1 |
=192.(rand(2)) |
Randomly generate a sequence of binary bits. |
2 |
=A1.bits() |
Convert A1 to a sequence of long numeric values. For instance: |
3 |
=[1,0,1,1].bits() |
Return [-5764607523034234880]. |
4 |
=[true,false,true,true].bits@b() |
Return [-5764607523034234880]. |
Description:
The inverse operation of A.bits() function; get value of the nth bit.
Syntax:
B.bits(n)
Note:
The function gets value of the nth bit; it is the inverse operation of A.bits() function.
Parameter:
B |
The value returned by A.bits(). |
n |
An integer representing the nth bit. |
Option:
@b |
Judge whether value of the nth bit in sequence B is 1; the function returns true when the bit value is 1; and returns false when it is 0. |
Return value:
0/1/Boolean
Example:
|
A |
|
1 |
=192.(rand(2)) |
Randomly generate a sequence of binary bits. |
2 |
=A1.bits() |
Convert A1 to a sequence of long numeric values. For instance: |
3 |
=A2.bits(61) |
Return 1. |
4 |
=A2.bits@b(61) |
Judge whether the 61th bit member of A2’s sequence is 1 and return true |
5 |
=192.(A2.bits(~)) |
Return same result as A1 does. |