bin2dec
Converts binary text to a decimal number.
Category: Language Fundamentals > Data Types
Syntax
d = bin2dec(b)
Reads b as a binary number and returns its value.
Description
The digits are weighted by powers of two, so '1011' is 8 + 0 + 2 + 1 = 11. Spaces in the text are ignored, which allows grouped digits such as '1010 0101'. Any other character is an error.
Because the result is a double, only values up to flintmax are represented exactly. Use dec2bin for the opposite direction.
Input arguments
b- Character vector, string, char matrix with one number per row, or cell array of character vectors, made of
0and1.
Output arguments
d- Double scalar or column vector with one value per number.
Example
Single and several numbers
bin2dec('1011')
bin2dec({'101','11'})
bin2dec('1010 0101')
Output
ans = 11
ans = 2×1
5
3
ans = 165