Menu
  • HOME
  • TAGS

using array to store big numbers

c,bignum

Your input loops have serious problem. Also you use i to count the length of both a and b, but you don't store the length of a. So if they type two numbers that are not equal length then you will get strange results. The losing of the first digit...

Convert a big number given as a string to an OpenSSL BIGNUM

c,openssl,bignum

unsigned char *p_str = "82019154470699086128524248488673846867876336512717"; BIGNUM *p = BN_bin2bn(p_str, sizeof(p_str), NULL); Use int BN_dec2bn(BIGNUM **a, const char *str) instead. You would use BN_bin2bn when you have an array of bytes (and not a NULL terminated ASCII string). The man pages are located at BN_bin2bn(3). The correct code would look...

Convert byte array to signed int64 in javascript

javascript,arrays,binary,bignum,int64

There is an implementation for converting hex string to Int64 (both signed and unsigned) here: LINK That code returns right result: javascript: new HexStringToInt64StringConverter(true).convert('a2921f66350ae040') // will return -6732283969128439744 same as BitConverter.ToInt64() in BCL ...

Is there an equivalent of Python's fractions.Fraction (bignum/arbitrary-precision fraction/rational number class)?

c++,math,fractions,bignum,arbitrary-precision

If you're using boost, you can use boost::rational in conjunction with boost::multiprecision::cpp_int (arbitrary-precision integer): #include <boost/rational.hpp> #include <boost/multiprecision/cpp_int.hpp> using boost::multiprecision::cpp_int; typedef boost::rational<cpp_int> fraction_t; For some reason, the constructor fraction_t("1", "2") doesn't work, although cpp_int("1") does, so if you need large int literals, you can use this helper function to not...

wrong BIGNUM initialization in OpenSSL

c,openssl,bignum

The error was at: BN_bin2bn((uchar*)"\x01\x02\**0x03**\0",3,p); BN_bin2bn((uchar*)"\x02\x03\**0x04**\0",3,B); BN_bin2bn((uchar*)"\x03\x04\**0x05**\0",3,a); It should be BN_bin2bn((uchar*)"\x01\x02\x03\0",3,p); BN_bin2bn((uchar*)"\x02\x03\x04\0",3,B); BN_bin2bn((uchar*)"\x03\x04\x05\0",3,a); ...

Error: Reference to undefined global `Num'

ocaml,bignum

If the toplevel is already launched, you can dynamically load the library: # #load "nums.cma";; # Num.mult_num;; - : Num.num -> Num.num -> Num.num = <fun> Another possibility (which will work for all third party libraries and will manage paths and dependencies for you) is to use ocamlfind. For this,...