Working with binary

Nov 25, 2010 at 7:29pm
Is there any "standard" way to store data as binary?
Last edited on Nov 25, 2010 at 7:41pm
Nov 25, 2010 at 9:40pm
You need to be more precise. You can store raw data in anything that's big enough
Nov 25, 2010 at 10:08pm
So, I wanted to make a genetic algorithm, using binary for the genes (1 if the gene is activated, 0 if not), so I wanted to know if there's a way to store a integer as binary in a variable by using some c++ function, so I don't have to write one function to convert decimal numbers to binary numbers...
Nov 25, 2010 at 10:37pm
If the number of binary digit is fixed you can use std::bitset ( It has interfaces to convert is to/from strings and longs )
Or you can keep the integer as it is and use the bitwise operators to get/set values of specific bits.
Nov 25, 2010 at 11:10pm
Uhm, ok, I'll use bitwise operators. Thank you for helping me o_~d
Topic archived. No new replies allowed.