base2dec
Converts text in a given base (2 to 36) to a decimal number.
Category: Language Fundamentals > Data Types
Syntax
d = base2dec(s, base)
Interprets s as digits in base and returns the value.
Description
Each character is looked up among the digits 0-9 and A-Z, and the value is accumulated as d*base + digit. A character that is not a valid digit for the base causes an error. Spaces inside the text are ignored.
The inverse operation is dec2base. For the common bases there are the shortcuts bin2dec and hex2dec.
Input arguments
s- Character vector, string, or cell array of character vectors holding the digits. Letters stand for digits above 9, in either case.
base- Integer from 2 to 36.
Output arguments
d- Double column vector with one value per input row or cell, or a scalar for a single piece of text.
Example
Different bases
base2dec('11120', 3)
base2dec('zz', 36)
base2dec({'11','zz'}, 36)
Output
ans = 123
ans = 1295
ans = 2×1
37
1295