base2dec
Convert text representation of base-n
integer to double value
Syntax
Description
converts the base-D
= base2dec(baseStr
,n
)n
integer represented by
baseStr
to the equivalent decimal number and returns it as a
double-precision floating-point value.
If baseStr
represents an integer greater than or equal to
flintmax
, then base2dec
might not represent it
exactly as a floating-point value.
Examples
Convert Text Representing Base-12 Value
Convert a character vector that represents a base-12 value to a decimal number.
baseStr = '1B';
D = base2dec(baseStr,12)
D = 23
Return Numeric Array
Create a string array that represents multiple octal, or base-8, values.
baseStr = ["1777" "172" "16"]
baseStr = 1x3 string
"1777" "172" "16"
Convert the octal values and return a numeric array.
D = base2dec(baseStr,8)
D = 1×3
1023 122 14
Input Arguments
baseStr
— Text representing base-n
numbers
character array | cell array of character vectors | string array
Text representing base-n
numbers, specified
as a character array, cell array of character vectors, or string array.
baseStr
represents base-n
digits 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.
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.
n
— Base of input representation
integer between 2 and 36
Base of input representation, specified as an integer between 2 and 36. For example,
if n
is 8, then baseStr
represents base-8
numbers.
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced before R2006aR2020b: Issue warning when input values are greater than or equal to flintmax
The base2dec
function issues a warning when input values are greater than or equal to flintmax
. In previous releases, base2dec
did not issue this warning.
base2dec
now issues a warning because inputs representing
integers greater than or equal to flintmax
might not be represented
exactly as double-precision floating-point values.
To convert values greater than flintmax
exactly, consider one of
these alternatives:
In place of scalar text inputs, use hexadecimal or binary literals representing the same values. When you write a value as a literal, MATLAB® stores it as an integer that represents the value exactly. For more information, see Hexadecimal and Binary Values.
To convert hexadecimal inputs greater than
flintmax
, you can use thesscanf
function with the%lx
operator. When you use%lx
, the converted values are integers that have theuint64
data type. These integers have enough storage to represent values greater thanflintmax
exactly..
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)