128 bit math

Discussion in 'C Programming' started by Bruce., May 29, 2007.

  1. Bruce.

    Bruce. Guest

    MS VC Developer Studio 2003.

    I have some rather large integer numbers, 128 bits, I need to crunch. I
    need to be able to add, subtract, multiply, and divide. In no case would
    the result exceed 128 bits. Test for equal, greater than, less than.

    I would use _int128 if it existed.

    The values are currently in byte arrays such as:

    unsigned char value[16];

    arranged little endian (least significant first).

    Anyone know of a quick and easy way to do this?

    Thanks,
    Bruce.
    Bruce., May 29, 2007
    #1
    1. Advertising

  2. "Bruce." <> writes:

    >MS VC Developer Studio 2003.


    >I have some rather large integer numbers, 128 bits, I need to crunch. I
    >need to be able to add, subtract, multiply, and divide. In no case would
    >the result exceed 128 bits. Test for equal, greater than, less than.


    >I would use _int128 if it existed.


    >The values are currently in byte arrays such as:


    >unsigned char value[16];


    >arranged little endian (least significant first).


    >Anyone know of a quick and easy way to do this?



    By treating the arrays as pairs of int64_t's ?
    When 64-bit machines were far less common, many used a library developed
    by Netscape to support 64-bit arithmetic using arrays of two 32-bit numbers.
    It was supported by a header file of prototypes and macros to account for
    endianness concerns.
    I suspect that much of that code could be reused for your application.

    --
    Chris.
    Chris McDonald, May 29, 2007
    #2
    1. Advertising

  3. Bruce.

    Bruce. Guest

    "Chris McDonald" <> wrote in message
    news:f3hvh3$rg3$...
    > By treating the arrays as pairs of int64_t's ?
    > When 64-bit machines were far less common, many used a library developed
    > by Netscape to support 64-bit arithmetic using arrays of two 32-bit
    > numbers.
    > It was supported by a header file of prototypes and macros to account for
    > endianness concerns.
    > I suspect that much of that code could be reused for your application.


    Any idea where I might find that code?

    Bruce.
    Bruce., May 29, 2007
    #3
  4. Bruce.

    Ian Collins Guest

    Bruce. wrote:
    > MS VC Developer Studio 2003.
    >

    Please don't multi-post on Usenet. Cross-post if you think your
    question is really appropriate for more than one group.

    --
    Ian Collins.
    Ian Collins, May 29, 2007
    #4
  5. Bruce.

    jacob navia Guest

    Bruce. wrote:
    > MS VC Developer Studio 2003.
    >
    > I have some rather large integer numbers, 128 bits, I need to crunch. I
    > need to be able to add, subtract, multiply, and divide. In no case would
    > the result exceed 128 bits. Test for equal, greater than, less than.
    >
    > I would use _int128 if it existed.
    >
    > The values are currently in byte arrays such as:
    >
    > unsigned char value[16];
    >
    > arranged little endian (least significant first).
    >
    > Anyone know of a quick and easy way to do this?
    >
    > Thanks,
    > Bruce.
    >
    >


    Use lcc-win32, it provides 128 bit numbers in the standard
    distribution

    http://www.cs.virginia.edu/~lcc-win32
    jacob navia, May 29, 2007
    #5
  6. Bruce.

    Guest

    On May 30, 7:31 am, jacob navia <> wrote:
    > Bruce. wrote:
    > > MS VC Developer Studio 2003.

    >
    > > I have some rather large integer numbers, 128 bits, I need to crunch. I
    > > need to be able to add, subtract, multiply, and divide. In no case would
    > > the result exceed 128 bits. Test for equal, greater than, less than.

    >
    > > I would use _int128 if it existed.

    >
    > > The values are currently in byte arrays such as:

    >
    > > unsigned char value[16];

    >
    > > arranged little endian (least significant first).

    >
    > > Anyone know of a quick and easy way to do this?

    >
    > > Thanks,
    > > Bruce.

    >
    > Use lcc-win32, it provides 128 bit numbers in the standard
    > distribution
    >
    > http://www.cs.virginia.edu/~lcc-win32

    Dear Bruce,

    Please try Intel 128 bit instruction(SSE /2/3) and 128 bit
    registers(XMM registers). You can use these instructions for 128 bit
    arithmetic. PADD*, PMUL* PSUB* etc are some of the instruction
    samples. Even AMD processors have these kind instructions. Please read
    the instructions manuals.

    Use _asm block to right assembly in VC2003.

    Thanks and regards,
    Amal P.
    , May 30, 2007
    #6
  7. There is a library available called GMP. It allows you to deal with
    integers of arbitrary precision (reals and rationals too).

    Here's the URL: http://gmplib.org/

    Regards
    Chris Saunders

    <> wrote in message
    news:...
    > On May 30, 7:31 am, jacob navia <> wrote:
    >> Bruce. wrote:
    >> > MS VC Developer Studio 2003.

    >>
    >> > I have some rather large integer numbers, 128 bits, I need to crunch.
    >> > I
    >> > need to be able to add, subtract, multiply, and divide. In no case
    >> > would
    >> > the result exceed 128 bits. Test for equal, greater than, less than.

    >>
    >> > I would use _int128 if it existed.

    >>
    >> > The values are currently in byte arrays such as:

    >>
    >> > unsigned char value[16];

    >>
    >> > arranged little endian (least significant first).

    >>
    >> > Anyone know of a quick and easy way to do this?

    >>
    >> > Thanks,
    >> > Bruce.

    >>
    >> Use lcc-win32, it provides 128 bit numbers in the standard
    >> distribution
    >>
    >> http://www.cs.virginia.edu/~lcc-win32

    > Dear Bruce,
    >
    > Please try Intel 128 bit instruction(SSE /2/3) and 128 bit
    > registers(XMM registers). You can use these instructions for 128 bit
    > arithmetic. PADD*, PMUL* PSUB* etc are some of the instruction
    > samples. Even AMD processors have these kind instructions. Please read
    > the instructions manuals.
    >
    > Use _asm block to right assembly in VC2003.
    >
    > Thanks and regards,
    > Amal P.
    >
    Chris Saunders, May 30, 2007
    #7
  8. Bruce.

    Bruce. Guest

    "Chris Saunders" <> wrote in message
    news:1fdf1$465ce049$480c9eef$...
    > There is a library available called GMP. It allows you to deal with
    > integers of arbitrary precision (reals and rationals too).
    >
    > Here's the URL: http://gmplib.org/


    Thanks for the link. I'll check that out.

    Bruce.
    Bruce., May 30, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruce.

    128 bit math?

    Bruce., May 29, 2007, in forum: C++
    Replies:
    5
    Views:
    494
    Ian Collins
    May 29, 2007
  2. akineko
    Replies:
    7
    Views:
    1,330
    akineko
    Dec 22, 2008
  3. Eric Sosman

    Re: Integer 128 != Integer 128 ??

    Eric Sosman, Oct 12, 2010, in forum: Java
    Replies:
    6
    Views:
    835
    Screamin Lord Byron
    Oct 13, 2010
  4. chankey pathak

    Re: Integer 128 != Integer 128 ??

    chankey pathak, Oct 13, 2010, in forum: Java
    Replies:
    0
    Views:
    846
    chankey pathak
    Oct 13, 2010
  5. VK
    Replies:
    15
    Views:
    1,162
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page