?
Solved

Convert to Binary

Posted on 2004-09-24
2
Medium Priority
?
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 33

Assisted Solution

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

Accepted Solution

by:
grg99 earned 1000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever thought of installing a power system that generates solar electricity to power your house? Some may say yes, while others may tell me no. But have you noticed that people around you are now considering installing such systems in their …
This article provides a brief introduction to tissue engineering, the process by which organs can be grown artificially. It covers the problems with organ transplants, the tissue engineering process, and the current successes and problems of the tec…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses

770 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