[.net] I need a 256-bit integer

Started by
15 comments, last by Sagar_Indurkhya 18 years, 8 months ago
Where do I get a 256-bit integer in C#? There's no BigInteger class like there is in Java.
Graphics make the game! 8-)
Advertisement
Here's a VB.Net library that has 256 bit integers, with full source code:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=403&lngWId=10
Are you sure you need 256-bit int's?
Keep in mind it's not exactly fast.
Out of curiosity, why do you need to store numbers as large as 115792089237316195423570985008687907853269984665640564039457584007913129639935?
After another search, I found some C# code that supports 256 bit integers:

http://www.codeproject.com/csharp/BigInteger.asp

Bob
Quote:Original post by Roboguy
Out of curiosity, why do you need to store numbers as large as 115792089237316195423570985008687907853269984665640564039457584007913129639935?


Most likely for encryption purposes.

Bob
Pretty weak encryption. Typically encryption libraries that need to manipulate large integers (such as RSA) use an integer library that allows for arbitrary sizes; The simplest method is a string integer library [integers stored and manipulated as ASCII strings]. More complex, but much faster, is a chunked integer library (i.e. stores integer as 64bit chunks representing specific digit ranges)
Actually, it's for a Chess AI, for storing a unique ID to a chess board state. I need at least 132 bits even after using Huffman encoding to completely represent a board in int form, which means even a 128-bit int is too small.
Graphics make the game! 8-)
Ok, it's 4 am, so I'm not going to argue about whether you need a 256 bit int for that. (One question that springs to mind, though, what are you going to do with all these states? It's not like you'd even be able to fit a single bool for each state on your HD. Just storing the ID's would take more harddrives than I care to count. 132 bits is a lot. And if you can't associate any data with the different states, then what good are they?)

But if you do go with this, it sounds like you wouldn't need to do any math on them, only comparisons (to see if it's the same id).
So wouldn't it be easier to just make a struct or array of 8 ints (or 5 ints should do), and then just compare each of them, rather than setting up big math libraries?
that's a good point, I'll just use a struct. By the way, I don't need to store every state, i'm just using these unique IDs to compare whether the state that I get back from a certain hash table location really is the state I want, because there are so many states there's bound to be collisions. Thanks
Graphics make the game! 8-)

This topic is closed to new replies.

Advertisement