Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt problem with hexdigit string #70

Open
Thanh-Binh opened this issue Jan 10, 2023 · 1 comment
Open

BigInt problem with hexdigit string #70

Thanh-Binh opened this issue Jan 10, 2023 · 1 comment

Comments

@Thanh-Binh
Copy link

BigInt header only does not work with hexdigit string like
std::string hexStr = "123456789abcdef123456789abcdef";
It is very kind of you to extend it.

Best thanks

@whym1here
Copy link

int get_val(char c) {
    assert(('0' <= c and c <= '9') or ('a' <= c and c <= 'f'));
    if ('0' <= c and c <= '9') 
        return c - '0';
    else
        return c - 'a' + 10;
}

BigInt hex_to_BigInt(const std::string& hex) {
    assert(!hex.empty());
    BigInt res = 0, p = 1;
    for (auto it = hex.rbegin(); it != hex.rend(); it++) {
        res += p * get_val(*it);
        p *= 16;
    }
    return res;
}

I had something similar to this in mind. Do we have any library specific optimizations?
Obviously we would need to handle lots of edge cases in original implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants