Solved

Convert to Binary

Posted on 2004-09-24
2
317 Views
Last Modified: 2012-05-05
Does anyone know an algorithm to convert a decimal STRING, (not a 'number') to it's binary equivalent?

i.e.: "4654879791" -> "100010101011100111101010000101111"
0
Comment
Question by:eternal_21
2 Comments
 
LVL 33

Assisted Solution

by:snoyes_jw
snoyes_jw earned 250 total points
ID: 12146326
Cast the string to a number.  Proceed as normal.
0
 
LVL 22

Accepted Solution

by:
grg99 earned 250 total points
ID: 12146484
You can't convert decimal to binary sequentially, a digit at a time, as each decimal digit expands across several binary digits.

the only way I can see is to add up the powers of ten til you get the whole number, then convert to binary:

Tot = 0;

for all digits:  Tot = Tot * 10 + this_digit;

while Tot isnt Zero:  if Tot is odd, print "1" else print "0";  divide Tot by two;

{ Then flip the paper over so you see the digits in reverse order!  }




0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

A Guide to the PMT, FV, IPMT and PPMT Functions In MS Excel we have the PMT, FV, IPMT and PPMT functions, which do a fantastic job for interest rate calculations.  But what if you don't have Excel ? This article is for programmers looking to re…
Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now