bits()

Read(89) Label: bits,

Here is how to use bits() functions.

bits()

Description:

Convert a number represented by a certain numeral system to a decimal number.

Syntax:

bits(xi,…)

Note:

The function converts a number of a certain numeral 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.

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.

First convert xi to an integer according to the rules of a certain numeral system if it is a string.

Parameter:

xi

An integer/string

Option:

@h

Convert xi to integer decimal number according to the rules of hexadecimal numeral system if it is the string

@d

First convert xi to an integer if it is the string and then calculate according to the rules of decimal numeral system

@n

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

Won’t convert to a decimal number and should work with another option to return the string forming the number of the corresponding numeral system

@b

Enable returning a long integer

@r

Enable putting lower bits before higher bits

Return value:

Numeric value/string

Example:

 

A

 

1

[1,0,1,1]

 

2

=bits(A1)

11; convert binary number 1011 to a decimal number

3

=bits("1011")

11; split the single string into a sequence. It is equal to  =bits("1","0","1","1")

4

=bits@d(1,1,1,5)

1115; convert 1115 to a decimal number

5

=bits@n(true,false,true)

5; convert binary number 101 to a decimal number

6

=bits@n(1,1,0,1)

13; convert binary number 1101 to a decimal number

7

=bits@h("A",1,1,5)

41237; convert hexadecimal number A115 to a decimal number

8

=bits@r(0XBB0D8196)

3138224534; the low-order b its go first

9

=bits@sd(12)

12; return a decimal number

10

=bits@sh(1212)

4bc; return a hexadecimal number

11

=bits@b(67546523567)

Return result as a long integer

A.bits()

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, where higher bits go ahead

Option:

@m

Enable parallel processing

@n

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]

A.bits(n)

Description:

Judge whether a specified bit member of a sequence of long numeric values is 1.

Syntax:

A.bits(n)

Note:

The function gets the nth bit member from a sequence of long numeric values A and judges whether it is 1.

Parameter:

A

A sequence of long numeric values

n

An integer representing the nth bit

Return value:

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)

Judge whether the 61th bit member of A3’s sequence is 1 and return true