Other

Octal
to decimal - Two methods in Matlab

Basics

To
convert a value from octal
to decimal (base 8 to base 10), we first need to
know what an octal
number is.

The octal system is a
numerical
system used in digital electronics.
In this system of numbers, the symbols are counted only from ‘0’ to
‘7’. In base 8 we only have eight different symbols (there are no
symbols such as '8' or '9').

Similarly, thedecimal system
(base 10) has ten symbols, '0' to '9' and the binary
system (base 2) has only two symbols, '0' and '1'.

The following table shows
the meaning of all the symbols in
the octal system and
the equivalents in the decimal and binary systems.

Table equivalents: decimal, octal
and binary numbers

You can see that from 0
to 7 a number in octal is exactly the same as it is in decimal, but
what if you need to go beyond 7?

Video

Here's
a video that explains you the concepts behind the numerical
equivalencies in different systems. After the video, we show you how to
code that in Matlab.

Solution 1. Conversion
from Octal to Decimal using the obvious way in Matlab

We can go from
octal to
decimal by using the function base2dec,
which
converts a base-N number string to a decimal
number. Its syntax is

base2dec('string', base)

The parameter base can be anything, not
only 8.

For example, base2dec('100', 8) produces
a 64 in decimal and
base2dec('1352',
8) produces
a 746.