I am coding a dynamic solution to a problem with buttons.
a button can be on or off. there are n buttons
so i thought of trying all possibilities of bits(1 or 0) of length n
for example for n=3
do you have any idea how i can iterate through all these for any n?
In case than you need an integer that represent what buttons are down and what are up, you can compute the number:
int i = a*1 + a*2 + a*4 + a*8 +...
This number is unique for every image of up-down buttons
That's why you're not understanding me. The C++ Standard formally states that the amount of bits "char" must represent is 8 at minimum (28). Therefore, any number of bits per byte is to be assumed. While 8 is usually the normal amount of bits that form a byte, this cannot be assumed as in some cases, this is purely implementation specific.
All that means is that a "char" is a minimum of 8 bits. This does not mean that any number of bits to a byte can be assumed.. it still holds true that 8 bits is a byte.. youre getting confused.. a char is not explicitly a byte, nor vice versa. So on one system say a char is made up of 12 bits. This does NOT mean that there are 12 bits to a byte.
All that means is that a "char" is a minimum of 8 bits.
1.7 The C++ memory model [intro.memory]
The fundamental storage unit in the C++ memory model is the byte. A byte is at least large enough to contain any member of the basic execution character set (2.3) and the eight-bit code units of the Unicode UTF-8 encoding form and is composed of a contiguous sequence of bits, the number of which is implementation defined.