bits()

Read(346) Label: decimal, numeric,

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.

Parameters:

xi

An integer/string

Options:

@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 absent and to 1 if the parameter is present, 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

Return value:

Numeric value/string

Example:

 

A

 

1

[1,0,1,1]

 

2

=bits(A1)

13; convert binary number 1101 to a decimal number

3

=bits("1011")

13. Split the single string into a sequence. It is equal to  =bits("1","0","1","1")

4

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

5111; convert decimal number 5111 to one of same numeral system

5

=bits@n(1,1,1)

11; convert binay number 1011 to a decimal number

6

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

15; convert binary number 1111 to a decimal number

7

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

20762; convert hexadecimal number 511A to a decimal number

8

=bits@sn(2,,1,1)

1101; return a binary number directly without converting to a decimal number

9

=bits@sd(12)

12; return a decimal number

10

=bits@sh(1212)

4bc; return a hexadecimal number