0% found this document useful (0 votes)
20 views

3.8. Converting Decimal Numbers To Binary Numbers - Problem Solving With Algorithms and Data Structures

This document discusses converting decimal numbers to binary numbers. It explains that computers store all values internally as binary digits (0s and 1s), so it is important to be able to convert between decimal and binary representations. It then introduces an algorithm called "Divide by 2" that uses a stack to keep track of the digits during the conversion process.

Uploaded by

EvanDave
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

3.8. Converting Decimal Numbers To Binary Numbers - Problem Solving With Algorithms and Data Structures

This document discusses converting decimal numbers to binary numbers. It explains that computers store all values internally as binary digits (0s and 1s), so it is important to be able to convert between decimal and binary representations. It then introduces an algorithm called "Divide by 2" that uses a stack to keep track of the digits during the conversion process.

Uploaded by

EvanDave
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

3/18/2018 3.8.

Converting Decimal Numbers to Binary Numbers — Problem Solving with Algorithms and Data Structures

  Problem Solving with Algorithms and Data Structures

Chapters

3.8. Converting Decimal Numbers to Binary


Numbers
In your study of computer science, you have probably been exposed in one way or another to the idea
of a binary number. Binary representation is important in computer science since all values stored
within a computer exist as a string of binary digits, a string of 0s and 1s. Without the ability to convert
back and forth between common representations and binary numbers, we would need to interact with
computers in very awkward ways.

Integer values are common data items. They are used in computer programs and computation all the
time. We learn about them in math class and of course represent them using the decimal number
system, or base 10. The decimal number \(233_{10}\) and its corresponding binary equivalent \
(11101001_{2}\) are interpreted respectively as

\(2\times10^{2} + 3\times10^{1} + 3\times10^{0}\)

and

\(1\times2^{7} + 1\times2^{6} + 1\times2^{5} + 0\times2^{4} + 1\times2^{3} + 0\times2^{2} +


0\times2^{1} + 1\times2^{0}\)

But how can we easily convert integer values into binary numbers? The answer is an algorithm called
“Divide by 2” that uses a stack to keep track of the digits for the binary result.

The Divide by 2

http://interactivepython.org/runestone/static/pythonds/BasicDS/ConvertingDecimalNumberstoBinaryNumbers.html 1/1

You might also like