Solved

Convert to Binary

Posted on 2004-09-24
2
319 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with the case study 6 59
Probability Distribution 8 57
Access question - internal training 9 60
Normalised finishing position 2 44
We are taking giant steps in technological advances in the field of wireless telephony. At just 10 years since the advent of smartphones, it is crucial to examine the benefits and disadvantages that have been report to us.
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

920 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

15 Experts available now in Live!

Get 1:1 Help Now