Thread: Large integers multiplications

  1. #1
    Registered User
    Join Date
    Oct 2010

    Large integers multiplications

    Hi All,

    I would like to ask question regards multiplying large integers. I would like to multiply two integers of size 32 bits and then multiply the result by 2. The output size should be of size three words each of size 32 bits.


    uint32_t a, b; // a and b is of size 32 bits;
    uint_t output; // here is my question, what size should i use for output? and how?

    output = (a * b) * 2;

    Then the size of output should be 32+32+32 (one bit only will be used from this 32) = 96 bits. How to create such output size? and how do define it?

    Hope its clear.

    Please support.

    Thanks a lot.

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    London, United Kingdom
    Either do everything yourself manually(i.e. have a struct with three partitions and do the multiplication manually), or the better option is to find some BigNum library that can support large integers.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    Mar 2010
    There might be a compiler specific extension you can use. For example GCC has a __int128, but the documentation says "There is no support in GCC to express an integer constant of type __int128 for targets having long long integer with less then 128 bit width." so I guess that's out (__int128 - Using the GNU Compiler Collection (GCC))

    It wouldn't be very difficult to write functionality to multiply two 96 or 128-bit types together. You could use partitions (e.g. 32 bit types) or just use an array of chars. It might take a bit of time though... so probably worth trying to find a library. The GNU MP Bignum Library will do it -- but it looks pretty big for what you want.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    I've been asked to write an __int128 extension for gcc by someone already. Still haven't gotten around to starting it yet though.
    In the mean time, I have my own big integer libraries on my website, which is miniscule compared to other libraries.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help assignment due tomorrow
    By wildiv in forum C Programming
    Replies: 6
    Last Post: 01-27-2010, 08:38 PM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. infinite looping when 2 large integers divide
    By Horse22 in forum C++ Programming
    Replies: 5
    Last Post: 01-08-2005, 11:25 AM
  4. Messing with Large Integers
    By johnnie2 in forum Windows Programming
    Replies: 3
    Last Post: 11-16-2002, 01:22 PM
  5. Storing large integers....why doesn't this work?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 09-21-2001, 09:41 PM