Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. BigNum

BigNum

Scheduled Pinned Locked Moved C / C++ / MFC
questionalgorithmsdata-structures
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndreFratelli
    wrote on last edited by
    #1

    Hi there guys! I wrote a BigNum class with two operations (addition and subtraction) and it consists of an array of integers. But lets suppose I read two numbers, with the following digit separation: 120 43 353 54 345 54 345 455 34 344 This is in base ten. Adding them together I get: 174 388 808 88 689 Which, obviously, is wrong. I used the standard addition algorithm, and it seems correct, so my question is: after "manipulating" the values, how can I print them correctly in base 10? Or do I need to keep a byte string with the digits and start from there? Best regards

    Fratelli

    D L D C 4 Replies Last reply
    0
    • A AndreFratelli

      Hi there guys! I wrote a BigNum class with two operations (addition and subtraction) and it consists of an array of integers. But lets suppose I read two numbers, with the following digit separation: 120 43 353 54 345 54 345 455 34 344 This is in base ten. Adding them together I get: 174 388 808 88 689 Which, obviously, is wrong. I used the standard addition algorithm, and it seems correct, so my question is: after "manipulating" the values, how can I print them correctly in base 10? Or do I need to keep a byte string with the digits and start from there? Best regards

      Fratelli

      D Offline
      D Offline
      Divyang Mithaiwala
      wrote on last edited by
      #2

      How you will read big num & fill it in array of int?

      AndreFratelli wrote:

      I used the standard addition algorithm

      Please past code over here.


      Do not trust a computer... Always check what computer is doing regards, Divyang Mithaiwala Software Engineer

      1 Reply Last reply
      0
      • A AndreFratelli

        Hi there guys! I wrote a BigNum class with two operations (addition and subtraction) and it consists of an array of integers. But lets suppose I read two numbers, with the following digit separation: 120 43 353 54 345 54 345 455 34 344 This is in base ten. Adding them together I get: 174 388 808 88 689 Which, obviously, is wrong. I used the standard addition algorithm, and it seems correct, so my question is: after "manipulating" the values, how can I print them correctly in base 10? Or do I need to keep a byte string with the digits and start from there? Best regards

        Fratelli

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Your "digit separation" does not make sense to me. Looks like you forgot the carry (even though you say you used the standard addition algorithm) Converting to base 10 is easy, but not trivial (you can not convert every integer to base 10 and then concat them, I hope you didn't even think of that as a possibility)

        1 Reply Last reply
        0
        • A AndreFratelli

          Hi there guys! I wrote a BigNum class with two operations (addition and subtraction) and it consists of an array of integers. But lets suppose I read two numbers, with the following digit separation: 120 43 353 54 345 54 345 455 34 344 This is in base ten. Adding them together I get: 174 388 808 88 689 Which, obviously, is wrong. I used the standard addition algorithm, and it seems correct, so my question is: after "manipulating" the values, how can I print them correctly in base 10? Or do I need to keep a byte string with the digits and start from there? Best regards

          Fratelli

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          AndreFratelli wrote:

          ...with the following digit separation: 120 43 353 54 345 54 345 455 34 344

          Is it normal to have some groups of 2 and others of 3?

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          1 Reply Last reply
          0
          • A AndreFratelli

            Hi there guys! I wrote a BigNum class with two operations (addition and subtraction) and it consists of an array of integers. But lets suppose I read two numbers, with the following digit separation: 120 43 353 54 345 54 345 455 34 344 This is in base ten. Adding them together I get: 174 388 808 88 689 Which, obviously, is wrong. I used the standard addition algorithm, and it seems correct, so my question is: after "manipulating" the values, how can I print them correctly in base 10? Or do I need to keep a byte string with the digits and start from there? Best regards

            Fratelli

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #5

            AndreFratelli wrote:

            120 43 353 54 345 54 345 455 34 344

            You digit separation doesn't make sense. Do your operations make sense, instead? :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups