# Conversion between Number Systems in Membrane Computing
## 3 Conversion between Decimal and Binary
### Decimal to Binary  
In order to implement the decimal-to-binary conversion, design the P system structure as (2). \[\Pi_{10\_2}=(V,\,\mu,\,\omega_{1},\,\mathrm{R},\,\mathrm{i}_{0}) \tag{2}\]  
where  
\(V=\{a,\,b,\,c,\,d,\,g,\,x,\,y,\,e,\,g,f\}\)  
\(\mu=[1_{1}[2]_{2}]_{1}\)  
\(\omega_{1}=\{a^{n}c\}\)  
\(\mathrm{i}_{0}=1\)  
\(\mathrm{R}=\mathrm{R}_{1}\cup\mathrm{R}_{2}\cup\mathrm{R}_{3}\)  
\(\mathrm{R}_{1}=\{\mathrm{r}_{1}\):\(a^{2}\)\(\rightarrow\)\(\mathrm{b}g\), \(\mathrm{r}_{2}\):\(c\)\(\rightarrow\)\(dx\}\)  
\(\mathrm{R}_{2}=\{\mathrm{r}_{3}\):\(a\)\(d\)\(\rightarrow\)\(f\)(1, \(out\)), \(\mathrm{r}_{4}\):\(b\)\(\rightarrow\)\(e\), \(\mathrm{r}_{5}\):\(gx\)\(\rightarrow\)\(gy\)  
\(\mathrm{R}_{3}=\{\mathrm{r}_{6}\):\(eg\)\(\rightarrow\)\(a\), \(\mathrm{r}_{7}\):\(yd\)\(\rightarrow\)\(c\)(0, \(out\)), \(\mathrm{r}_{8}\):\(yd\)\(\rightarrow\)\(c\)\(\}\)  
\(a,\,b,\,c,\,d,\,e,\,g,\,x,\,y,\) and \(f\) are objects in the system. \(n\) is the number of decimal digits converted to binary. Membrane 1 is where the output results are stored. To visualize this specific P system used to convert decimal to binary, Figure 2 shows its architecture. \(\Pi_{10\_2}\) converts the decimal number \(n\) to a binary string. Initially, \(n\) objects \(a\) (multisets \(\{a^{n}\}\)) and one object \(c\) are placed in membrane 2. Rule set \(\mathrm{R}\) of \(\Pi_{10\_2}\) is divided into three subsets. \[\mathrm{R}=\mathrm{R}_{1}\cup\mathrm{R}_{2}\cup\mathrm{R}_{3} \tag{3}\]  
where  
\[\mathrm{R}_{1}=\{\mathrm{r}_{1},\,\mathrm{r}_{2}\},\cdots\mathrm{R}_{2}=\{ \mathrm{r}_{3},\,\mathrm{r}_{4},\,\mathrm{r}_{5}\},\,\mathrm{R}_{3}=\{ \mathrm{r}_{6},\,\mathrm{r}_{7},\,\mathrm{r}_{8}\}\]  
\(\mathrm{R}_{1},\,\mathrm{R}_{2},\) and \(\mathrm{R}_{3}\) correspond to the rules executed in each of the 3 time slices of \(\Pi_{10\_2}\) the execution. Every three time slice \(\Pi_{10\_2}\) completes a loop to achieve the number of objects \(a\) in membrane 1 divided by 2 and outputs a 1-bit binary number to the environment (the order of output is from low to high) until the number of objects \(a\) in membrane 2 is zero. When we convert the decimal number \(n\) (represented as \(a^{n}\) in membrane 2) to binary, the execution process of \(\Pi_{10\_2}\) is as follows:  
(1) The first time slice. The rules in \(\mathrm{R}_{1}\) are executed simultaneously; however, one of the special cases is that when \(\mid a\mid<2\) (the quantity of object \(a\) is denoted as \(\mid a\mid\)), only r  
Figure 2: P system for decimal to binary. meets the execution conditions. When r\({}_{1}\) is executed, the number of objects \(a\) in membrane 1 is divided by 2 and produces \(\mid\!a\!\mid/2\) objects \(b\) and \(g\) (the number of objects \(b\) and \(g\) represents the quotient of decimal number \(n\) divided by radix 2). If \(n\) is an odd number, there will be 1 object \(a\) left in membrane 1 (the number of \(a\) represents the remainder after r\({}_{1}\) is applied). When r\({}_{2}\) is executed, consuming object \(c\) generates objects \(d\) and \(x\). (2) The second time slice. The rules in R\({}_{2}\) will be selected for execution. If there is object \(a\) in membrane 2, r\({}_{3}\), r\({}_{4}\), and r\({}_{5}\) will be applied; otherwise, only r\({}_{4}\) and r\({}_{5}\) will be executed. The rule r\({}_{3}\) generates objects \(f\) and outputs a 1-bit binary number '1' to the environment. Rule r\({}_{4}\) executes, converting \(\mid\!a\!\mid/2\) objects \(b\) to \(\mid\!a\!\mid/2\) objects \(e\). Rule r\({}_{5}\) executes, converting objects \(x\) and \(g\) to objects \(y\) and \(g\). After the second time slice, the number of \(g\) remains unchanged, which is still \(\mid\!a\!\mid/2\). (3) The third time slice. The rules in R\({}_{3}\) will also be selected for execution. If there is object \(d\) in membrane 2, r\({}_{6}\) and r\({}_{7}\) are applied, or r\({}_{6}\) and r\({}_{8}\) will be executed. Rule r\({}_{6}\) consumes and converts \(\mid\!a\!\mid/2\) objects \(e\) and \(g\) into \(\mid\!a\!\mid/2\) objects \(a\) in preparation for the next cycle.