开发者

how to implement unsigned 33 bit integer type

Is there any way to implement 33 bit unsigned integer for gcc compiler? As of now I am using unsigned 64 bit integer to store 33 bit value. But unfortunately i want the value to be reset开发者_如何学Python after it reaches full 33 bits...


You could use a bit field, e.g. (result)

#include <stdint.h>
#include <cstdio>

struct uint33_t {
    uint64_t value : 33;
};

int main() {
    uint33_t x = {0x1FFFFFFFFull};

    printf("%llx\n", x.value);

    x.value += 1;

    printf("%llx\n", x.value);


        return 0;
}


struct int33
{
   unsigned long long x:33;
};

?


The value will overflow when it is pushed beyond the 33-bit boundary; if you use a 33-bit mask when fetching the value you should get the behavior you want.


I wrote some code dealing with this:

http://bitbucket.org/pnathan/logic-vector

You are free to look it over. If you modify/improve it please patch back. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜