By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,442 Members | 1,437 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,442 IT Pros & Developers. It's quick & easy.

128 bit math

P: n/a
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.
May 29 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"Bruce." <no***@nowhere.comwrites:
>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.
May 29 '07 #2

P: n/a
"Chris McDonald" <ch***@csse.uwa.edu.auwrote in message
news:f3**********@enyo.uwa.edu.au...
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.
May 29 '07 #3

P: n/a
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.
May 29 '07 #4

P: n/a
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
May 29 '07 #5

P: n/a
On May 30, 7:31 am, jacob navia <j...@jacob.remcomp.frwrote:
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 '07 #6

P: n/a
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

<en********@gmail.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
On May 30, 7:31 am, jacob navia <j...@jacob.remcomp.frwrote:
>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 '07 #7

P: n/a
"Chris Saunders" <ev**@mountaincable.netwrote in message
news:1f***************************@MOUNTAINCABLE.N ET...
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.
May 30 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.