# $2^1 + 2^2 + \cdots + 2^8$ in binary

Maybe these are silly question. I know almost nothing about computer science, so please let me know in the comment section if I should edit anything or delete it.

1. Let's say I have a function that randomly selects 8 choices of 0 or 1. Would it be written as one byte together? For example, if all choices came out as 1, would it be written as 11111111?

2. Also, let's say another function can select the amount of choices. Any between 1 and 8 choices of either 0 or 1. As an example, if 3 choices were selected and all came out as 1, will it be written as 111? If so, how will the program know when to go to the next function in the case that every function had to select between 1 and 8 choices of 0 or 1?

• What you describe can be represented by an 8-bit integer. Assuming it's non-negative, that integer would have a range between 0 and 2^8+2^7+...+2^0=511, to a total of 512 representable numbers. Any random number in that range would give you different combinations of zeros and ones – Nikos Kazazakis Mar 18 '17 at 6:28
• What I understand from the given description is that you have two function say f1 and f2. f1 generate 8 random bits. f2 select (not given how) a number between 1 to 8 and that many bits will be selected. In your example it is all 1s so you can select any three bits. But which three bits will be selected if there is some other bits. For function f1 you can generate an 8 bit number. – Deep Joshi Mar 18 '17 at 6:38
• nikaza, Thank you for taking your time. I don't understand. I thought 8 bits were 2^8, 256. What I wanna know is how it will look in binary if I had 3 choices, then 2, then 5 and so on, each being from a different function. – Forrest Gump Mar 18 '17 at 6:40
• @Deep Joshi Thank you for commenting. I think I didn't explain it correctly. f1 (I think you got from question 1) was to see if I'm correct in thinking that it will be written as 8bits together. f2 (maybe you refer to question 2), this is the only type of function to be used. Let's say there are 4 functions that randomize 0 or 1 in any random amount. If they come up with amounts f1 (4), f2 (2), f3 (6) and f4 (3), will they be written as f1 (0110), f2 (11), f3 (011000) and f4 (110)? – Forrest Gump Mar 18 '17 at 7:00
• @nikaza, Thank you for taking your time. I don't understand. I thought 8 bits were 2^8, 256. What I wanna know is how it will look in binary if I had 3 choices, then 2, then 5 and so on, each being from a different function. – Forrest Gump Mar 18 '17 at 7:02

In the binary system (much like in all numbering systems), order has meaning. If you write $0110$ this means $0\times2^3+1\times2^2+1\times2^1+0\times2^0$. Similarly, $11111111$ means $1\times2^7+1\times2^6+1\times2^5+1\times2^4+1\times2^3+1\times2^2+1\times2^1+1\times2^0=255$.