Two's complement in libtommath library
I am using libtommath library for bigInteger calculation for my iphone application. I have used libtommath library to implement Diffie-Hellman key exchange.
On server sider, the code is in java, which uses Biginte开发者_JAVA百科ger class. In Biginteger class, there is a function toByteArray. This function takes the two's complement and returns the byte array.
I want to do similar stuff on my iphone app. Can anyone tell me how to take two's complement in big integer calculated by libtommath.
In other words,
Say Output of my calculation is in NSString *bobkey = "325522525225322525234444445646456564564654654654654654654744797239797297421749179472974721974127439729749274972974927497297439274972974927497274927497329473927497294729847289749827917974291734927149792749724972397927394797324927493274927";
Now how do i get two's complement of above number that matches with the byte array of BigInteger ?
Can you clarify what you're trying to do? Part of twos complement is the precision you're dealing with, which is theoretically unlimited in BigNum packages.
Regardless, in most numerical representations, the two's complement is just the binary representation of the negated value minus 1. i.e. -1 == two's complement of 0 (or 2^n - 1 - 0 = complement(0))
精彩评论