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 decimal to binary string

As we have discussed in the previous section, the binary string of 9 is 1001. We can convert a decimal number into a binary digit by dividing the number by 2 until it cannot be divided any more, and collect the remainder of each division. Here's the steps to convert 9 into binary digit:

9 is divided by 2 is 4, remainder is 14 is divided by 2 is 2, remainder is 02 is divided by 2 is 1, remainder is 01 is divided by 2 is 0, remainder is 1

Look at the remainder of each division, and read it from the bottom to the top. So that's why we have 1001 as a binary digit of 9. Now, let's try another larger number, which is 500. Here are the steps to convert 500 to binary digit:

500 is divided by 2 is 250, remainder ...
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