0

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.)

user1111929
  • 6,050
  • 9
  • 43
  • 73
  • http://stackoverflow.com/questions/2611764/can-i-use-a-binary-literal-in-c-or-c – user123 Jun 15 '13 at 22:43
  • 1
    http://stackoverflow.com/questions/15114140/writing-binary-number-system-in-c-code/15114188#15114188 –  Jun 15 '13 at 22:44

1 Answers1

2

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?

Community
  • 1
  • 1
Macattack
  • 1,917
  • 10
  • 15