Thread: quest..

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    16

    Question quest..

    I'm writing this class call hugeint, and part of writing this class is having function like add, subtract, multiply... So far i cover +,-,*,<,>,==,!= but when it comes to division i dont think i'm doin' it the best way. What i done so far is ask for 2 number (whithin' a 40 digit limit) and subtract the 2 numbers until the first is less than the second and keep track of how many times i've subtracted the numbers and return the count.
    My question is how does a computer divide to integers, lets say 25 and 5??

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    You can divide binary numbers the same way you divide base-10 numbers. Floating point division is much different.
    Code:
       25 / 5
    11001 / 101
    
      11001
    - 101    -> 1
    -------------
        10   -> 0
    -------------
        101
    -   101  -> 1
    
    11001 / 101 = 101
    Here's another example:
    Code:
     28 / 3
    
    11100 / 11
    
      11100
    - 11     -> 1
    -------------
       01    -> 0
    -------------
       010   -> 0
    -------------
       0100
    -    11  -> 1
    -------------
          1
    ran out
    
    11100 / 11 = 1001 R1
    
    1001 = 9
    9 * 3 = 27
    
    1 = 1
    Remainder 1
    In other words, use long division.
    Last edited by Speedy5; 04-08-2004 at 04:54 PM.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    This applies specifically to binary numbers, but maybe it'll help...

    http://courses.cs.vt.edu/%7Ecs1104/D....Subtract.html

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Thats what I did.

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    16
    I see what y'all saying but how would I divide a huge integer like 1234564231 / 124578??
    Another thing i didn't mention is that the hugeint i kept in an array...
    Thanx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MoveToEx() & LineTo() functions
    By csonx_p in forum Windows Programming
    Replies: 17
    Last Post: 04-11-2008, 12:53 AM
  2. Peasant's Quest Walkthrough
    By sean in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 09-25-2004, 06:46 AM
  3. Space Quest 7
    By sean in forum Projects and Job Recruitment
    Replies: 4
    Last Post: 07-27-2004, 08:26 PM
  4. Quest for the Quests
    By sean in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 11-16-2002, 12:18 AM
  5. Space, Police, and King's quest.
    By sean in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 07-02-2002, 12:33 PM