Hi everyone,

I was wondering if anyone could provide a bit of help,

I need to store an integer value that is 20 bytes in length - I know theres an int32_t and int16_t, but I can't seem to get an integer stored that is only 20 bytes!!

I've also tried storing them in a 20 char array - unfortunately returning it from the class is proving to be a bit of a problem (I need to store the integer first in the class itself, then everything from the class is copied into a struct so it can be converted into binary)

Any help would be much appreciated, I can post some code online as well if anyone wishes to have a look at it - here is the code for the attempt I made at making a 20 byte integer, but it keeps returning an error that it has exceeded it's width :(

struct int20
{       
        unsigned long _int20 : 160;
};

Um, 20 bytes is well beyond the range of C++'s built-in types. I suspect you want an arbitrary length math library like GMP.

Do you want an integer that is 20-Bytes or 20-Bits? The int32 and int16 types are 32- and 16-Bits respectively.

Need it to be an integer that can hold 20 bytes, I was trying to store it into a 20 byte char array but I can't seem to get it to return from the class it's stored in

Listen to Narue. You need a bignum library. If you must fix it to exactly 20 bytes worth of data, then you can write your own simple class, or you can google around it to find some that others have written. The GMP is pretty much industry standard. There are others also, like TTMath.

Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.