sercantutar / infint

Arbitrary-Precision Integer Arithmetic
http://sercantutar.github.io/infint/
201 stars 49 forks source link

Support for Hex? #13

Open ry4ng opened 7 years ago

ry4ng commented 7 years ago
InfInt myHex1 = "7649f43c17e43e08446ce5b3119f905acc4e380233e8e96f0468f12aa2b249fa";
myint1++;
cout << myHex1 << endl

7649f43c17e43e08446ce5b3119f905acc4e380233e8e96f0468f12aa2b249fb

Allow the incrementation of huge hex values?

kozubik commented 7 years ago

this might help you

` void InfInt::addHexString(const char* s) { if(s == NULL) return;

size_t hex_len = strlen(s);

InfInt temp(0);
InfInt base(0);
for(size_t i = 0; i < hex_len; i++)
{
    char ch = s[hex_len - i - 1];
    unsigned char dec = 0;

    //ascii conversion of each character
    if(ch >= 48 && ch <= 57)            dec = ch - 48;
    else if(ch >= 65 && ch <= 70)       dec = ch - 55;
    else if(ch >= 97 && ch <= 102)      dec = ch - 87;

    size_t exp = i;
    base = 16;
    temp = dec;
    while(exp != 0)
    {
        if((exp & 1) == 1)
            temp *= base;

        exp >>= 1;
        base *= base;
    }

    (*this) += temp;
}

} `

i tested it with 3581bit number and it's working EDIT: rewritten to a method