# About the spaces between bits

Let's say I have three functions and each gives true/false answers. The first one gives 2 booleans, the second 6 and third 4. Are they written like this: 01 110010 1000? Do they get spaces between the functions? If so, do the spaces count as data? What I wanna know is, if you send an encryption key using RSA, how does RSA recognize the length of your key with the spaces? Another way to put it is if a symmetric key has 256 functions of one bit each (0 1 1 0 0 1 0, etc.) would it end up being 512 bits long because of the spaces?

I'm new in computer science and I'm learning for fun by myself. I apologize if my question is the smh type.

## 1 Answer

First of all, encoding is up to you — you get to decide the answer to the question you state.

Let's consider a more generic situation, in which you want to serialize (convert to bits) a sequence of values $x_1,\ldots,x_k$. If you know ahead of time what the length of $x_i$ is, then the most efficient encoding would be to put together all the bits of all values (no spaces!). (In practice, we also need to pack them into bytes, since data is passed around in byte chunks.)

If you don't know the length in advance, then there are several option. One option is to use some self-terminating encoding. For example, you could preface each bit by 0, and end the stream by a 1. A 2-bit string $b_0b_1$ would be encoded by $0b_00b_11$. Such an encoding is not very common. Another option is to store the length somewhere — this is quite common. For example, JPEG files store the dimension of the picture in a header. A third option is that the length, while not predetermined, is one of very few options. In that case it suffices to store just the index of the option in some header. This is probably what happens in cryptographic protocols.

Finally, there seems to be a basic misunderstanding in your question. Information is passed around in bytes. When you have a stream of bits, you pack them into chunks of 8 bits and send them in that way. There are only two options for bits — they can be either 0 or 1. What beginners sometimes do is send the bitstream as an ASCII or Unicode string, which does accept 0s, 1s, and spaces (as well as many other letters). However, this is very wasteful, spending at least 8 bits per one input bit.