9 years, 7 months ago.

Array and binary elements

How can I store a binary number in an array i.e. the array element is either a 1 or a 0. Appreciate any help

may be by using bitset c++. search for C++ bitset on the web. It's very usefull to manipulate bit strcutures

http://www.cplusplus.com/reference/bitset/bitset/bitset/

posted by Raph Francois 06 May 2015

1 Answer

9 years, 7 months ago.

You can either use an array of type bool or use an array of chars and use values of 0 or 1. Either way you will use up 1 byte per array entry.

If you want to store 8 bits per byte then you need to create your own code that uses binary masks to pack the data.

Accepted Answer