Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6910293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:47:45+00:00 2026-05-27T08:47:45+00:00

I’d like to write (not to use existing one) a library (or something) that

  • 0

I’d like to write (not to use existing one) a library (or something) that works with long numbers (I mean at least few hundred digits).

The first question: choosing a language for it. Which one is better: Perl/JavaScript/PHP?

The second question: how to implement operations with long numbers? The only thing I get is to work with them as with arrays, e.g.:

arr1 = (12, 34); //1234
arr2 = (98, 76); //9876
sum = longnumbers_add(arr1, arr2); // +
// 34 + 76 = 110 = 10 -..> 1
// 12 + 98 = 110 = 110 + 1 = 11 -..> 1
//sum == (1, 11, 10);

But it worked to slow (at least with my try in PHP). Maybe there’s some “shift bits” super-fast method?

P.S.

I know there are gmp and other cool libraries.

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:47:46+00:00Added an answer on May 27, 2026 at 8:47 am

    I’ve written a couple big number libraries for fun. As far as the language, I would either choose whichever one you’re most comfortable with or one you want to learn more about. For me, that was JavaScript most recently, but in my opinion, none of those languages are any more or less suited to large numbers. For the web though, a large part of the decision comes down to whether you want to do the calculations on the client or server side. On the client side, JavaScript is pretty much the only option.

    I wrote a couple blog posts demonstrating the basic algorithms and how I chose to store them. Note that these are for big integers only (so no decimal point), but the basics still apply.

    • http://silentmatt.com/blog/2011/10/how-bigintegers-work/
    • http://silentmatt.com/blog/2011/10/how-bigintegers-work-part-2-multiplication/

    Here are a few thoughts from my experience:

    • It’s probably easiest conceptually to store the numbers in base 10 because it’s more familiar, but it really doesn’t change much of the implementation. Larger bases are more efficient though (in both memory and speed).
    • It’s almost always simpler to keep the digits in “little endian” order, so the least significant digit comes first in the array (or if you used strings, store them reversed).
    • Don’t worry too much about performance until you get it working. The fastest way to do things can sometimes be surprising so you’ll get it wrong anyway, and it’s easy to go back and optimize each operation once you’re done.
    • If you want to support decimals, it can be easiest to write an integer type first, then implement floating point numbers on top of that. Basically, you can separate out the code to keep track of decimal places so it keeps the algorithms cleaner.
    • You’ll need to decide if you want to use two’s complement (10’s complement, or the equivalent for whatever base you choose also works) or sign-magnitude (where you store the sign separately from the digits) for handling negative numbers. Each method is more complicated in some areas and simpler in others. Generally though, n’s-complement is probably simpler if you have a fixed size, but sign-magnitude might be simpler for arbitrarily-sized numbers.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I would like to count the length of a string with PHP. The string
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.