hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Binary <-> Decimal Conversion
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Binary <-> Decimal Conversion

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 10-14-2002, 09:54 AM
Icheb Icheb is offline
Junior Guru Wannabe
 
Join Date: Oct 2002
Posts: 36

Binary <-> Decimal Conversion


At the moment I am trying to find a method which allows me to convert a large binary number (about 5 billion digits) into a decimal number extremely precise. The program language is not so relevant, it can be C or PHP or whatever possible.
I know there will a memory problem, but how can I calculate the amount of memory needed to store such a number?
And more important, does someone know of a method to convert such a number?

Reply With Quote


Sponsored Links
  #2  
Old 10-14-2002, 10:30 AM
nexcess.net2 nexcess.net2 is offline
Junior Guru Wannabe
 
Join Date: Oct 2001
Posts: 33
Did you say 5 billion digits? That isn't a "large" number... That is a ridiculous number.

If it were a 1 followed by 5 billion zero's, it would be 2^(5 billion), which is close enough to infinity for me.

This sounds like one of those "get a guaranteed A in class if you solve this" problems. Well, guess what? Nobody every does.

That said, if my life depended on this problem, I would investigate using LISP. My only reason for saying that is I have a vague memory of reading about being able to generate crazy big numbers without sucking up memory with LISP. If I find where this memory is coming from I'll let you know. But don't count on it.

Good luck,
Paul

__________________
Paul Oehler
http://nexcess.net


Last edited by nexcess.net2; 10-14-2002 at 11:16 AM.
Reply With Quote
  #3  
Old 10-14-2002, 10:56 AM
Icheb Icheb is offline
Junior Guru Wannabe
 
Join Date: Oct 2002
Posts: 36
Ok, I'll try to find something about LISP, thank you.

But how would you calculate the amount of memory needed to store and/or process such a large number?

Reply With Quote
Sponsored Links
  #4  
Old 10-14-2002, 05:43 PM
wave wave is offline
Junior Guru Wannabe
 
Join Date: Jul 2001
Posts: 64
Its easy to calculate the memory needed to store a binary number. Suppose your binary number has 5 billion binary digits. So it will take at least 5 billion bits or 6.25E8 bytes to represent such a number.

To calculate how much memory is needed to store the decimal equivalent is slightly more complicated. It depends on how your numbers are represented. Say we want to represent decimal digits in C using char - typically it takes 1 byte per char. We'll keep the answer simple and only worry about unsigned integers. A x bit binary number can represent decimal values from 0 to 2^x - 1. We'll find the maximum memory we need to store a decimal number (say N) that is equivalent to a 5 billion bit binary number

2^(5E9) = N + 1
(5E9)log2 = log(N + 1)
10^(1.6E9) >= N

Thus N will have at most 1.6E9 + 1 digits. Since each digit is represented by a char, it will take 1.6E9 + 1 bytes or 1.6GB to store N. Unless you have lots of memory to work with you'll need to use your disk. It shouldn't be difficult to program since you're only converting a number to a different base.


Last edited by wave; 10-15-2002 at 06:53 PM.
Reply With Quote
  #5  
Old 10-14-2002, 06:54 PM
wave wave is offline
Junior Guru Wannabe
 
Join Date: Jul 2001
Posts: 64
Sorry I made a mistake. It should have been N + 1 rather than N - 1. Please feel free to ask if you don't understand.


Last edited by wave; 10-15-2002 at 06:53 PM.
Reply With Quote
  #6  
Old 10-15-2002, 02:07 PM
dynamitehost dynamitehost is offline
WHT Addict
 
Join Date: Jul 2002
Location: UK
Posts: 169
Quote:
Originally posted by wave
Its easy....



2^(5E9) = N - 1
(5E9)log2 = log(N - 1)
10^(1.6E9) >= N
Errr.... yes

Reply With Quote
  #7  
Old 10-15-2002, 06:02 PM
weeps weeps is offline
Web Hosting Guru
 
Join Date: Apr 2002
Location: Canada
Posts: 283
I agree with wave. Easy.. basic math :-)

__________________
Jason Mansfield - jmansfie [at] uoguelph.ca

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Lead Generation Part 4 – Go it Alone Blog 2013-03-25 09:16:50
Web Host Lunarpages Partners to Provide SEO Services to Customers Web Hosting News 2012-10-26 16:31:31
How Website Design Affects Conversion Rates Blog 2012-09-28 13:52:36
Web Host A Small Orange Partners with Conversion Analytics Firm Spring Metrics Web Hosting News 2011-10-20 20:26:38
Landing Page Practices to Improve Marketing ROI with Tim Ash of SiteTuners Web Hosting News 2011-08-09 22:20:06


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?