Hello, how do you go about working with 128 bit numbers in C?
Hello, how do you go about working with 128 bit numbers in C?
You would use or write a fixed precision arithmetic library that supports 128 bit numbers, or an arbitrary precision arithmetic library like GMP.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I need to be able to write the code myself.
So, you basically want to write your own bignum library?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
So you should probably write some library to do it. Could be a number of ways of going about it.
For instance, how could i store the 128 bit number?
In an array. The question is an array of what, and that depends on your approach. For example, you could make it a string, and this would make it pretty trivial to read and write, but operations would be relatively slow.For instance, how could i store the 128 bit number?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Would that involve representing the number as a binary number in order to store it in an array?
It's not particularly hard to add/subtract big numbers [a 128 bit number using long long -> 64 bit numbers should be two add or sub operations, plus a quick check for overflow].
Division is a bit more tedious, as it would involve [at least] 128 shift operations - by far not impossible, but a bit lengthy.
Multiply ends up on the "inbetween" scale.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
So do I use binary?
How should I know, but I think it makes sense.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.