base2dec

Convert text representing number in base N to decimal number

Description

example

D = base2dec(baseStr,n) converts baseStr to a decimal number and returns it. The input argument baseStr represents digits of a base-n number using numeric characters and, when n is greater than 10, letters. For example, if n is 12, then baseStr represents the numbers 9, 10, and 11 using the characters '9', 'A', and 'B', and represents the number 12 as the character sequence '10'. Letters can be either uppercase or lowercase.

Examples

collapse all

Convert a character vector that represents a base-12 value to a decimal number.

baseStr = '1B';
D = base2dec(baseStr,12)
D = 23

Create a string array that represents multiple octal, or base-8, values.

baseStr = ["1777" "172" "16"]
baseStr = 1x3 string array
    "1777"    "172"    "16"

Convert the octal values and return a numeric array.

D = base2dec(baseStr,8)
D = 1×3

        1023         122          14

Input Arguments

collapse all

Text representing base-n numbers, specified as a character array, cell array of character vectors, or string array.

  • If baseStr is a character array with multiple rows or a cell array of character vectors, then the output is a numeric column vector.

  • If baseStr is a string array, then the output is a numeric array that has the same dimensions.

baseStr cannot represent a negative number.

Base of input representation, specified as an integer between 2 and 36.

Tips

  • If the input argument baseStr represents a value greater than the value returned by flintmax, then base2dec might not return an exact conversion.

Introduced before R2006a