Question

I have a large binary vector that I would like to enter hardcoded in a C-file, as an array of longs. My question is: what is the easiest way to do this? Is there something like uint64_t b = 0xb01111111011100001011100001011011; to convert the 01111111011100001011100001011011 from 64 bits to 1 long containing them? Or how should I do this?

(I need to do XOR/popcnt operations on such bitvectors, so they should be preserved exactly.)

Was it helpful?

Solution

I would recommend looking at this answer regarding entering binary into C and C++, Can I use a binary literal in C or C++? .

Depending on your compiler/platform, gcc supports this: http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html

 i =       42;
 i =     0x2a;
 i =      052;
 i = 0b101010;

All are equivalent.

Alternatively, would it be possible to just store these into a binary file which you read in on startup?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top