Skip to Content
C++ Data Structures and Algorithms
book

C++ Data Structures and Algorithms

by Wisnu Anggoro
April 2018
Intermediate to advanced content levelIntermediate to advanced
322 pages
6h 57m
English
Packt Publishing
Content preview from C++ Data Structures and Algorithms

Converting binary string to decimal

In this section, we are going to write a code to convert binary string into a decimal number. To do this, we are going to use 2 to the power of n formula (2n) to get the decimal value. We will multiply the last digit of the binary digit with 20, then multiply the next binary digit with 21, and so on.

Let's use our binary digit from the previous section, which is 111110100, and convert it to a decimal number. Please see the following diagram to find out the answer:

We will get the decimal number by adding all the results of 2n multiplication. So, 256 + 128 + 64 + 32 + 16 + 0 + 4 + 0 + 0 equals 500.

Now, let's ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Data Structures and Algorithms Using C++

Data Structures and Algorithms Using C++

Ananda Rao Akepogu, Radhika Raju Palagiri
C++ Data Structures and Algorithm Design Principles

C++ Data Structures and Algorithm Design Principles

John Carey, Anil Achary, Shreyans Doshi, Payas Rajan
C++ Plus Data Structures, 6th Edition

C++ Plus Data Structures, 6th Edition

Nell Dale, Chip Weems, Tim Richards

Publisher Resources

ISBN: 9781788835213Supplemental Content