# Conversion between Number Systems in Membrane Computing
## 3 Conversion between Decimal and Binary
### Binary to Decimal  
The P system to implement binary-to-decimal conversion up to \(n\) bits can be constructed as (4):  
\[\Pi_{2\_10}=(V,\,\mu,\,\omega_{1},\,\mathrm{R},\,\mathrm{i}_{0}) \tag{4}\]  
where:  
\(V=\{a,\,b,\,c,\,d,\,e,\,p,\,q,\,r,\,x,\,y,\,z,\,\lambda\}\)  
\(\mu=[1]_{1}\)  
\(\mathrm{o}_{1}=[a]\)  
\(\mathrm{i}_{0}=1\)  
\(\mathrm{R}=\mathrm{R}_{1}\cup\mathrm{R}_{2}\cup\mathrm{R}_{3}\cup\mathrm{R}_{4}\)  
\(\mathrm{R}_{1}=[\mathrm{r}_{1}:\!\!0a\!\!\to\!\!\!\mathit{bcr},\,\mathrm{r}_{2} :\!\!1a\!\!\to\!\!\!\mathit{bcr}]\)  
\(\mathrm{R}_{2}=[\mathrm{r}_{3}:\!\!0b\!\!\to\!\!\!\mathit{p}x^{2(n-1)}c^{2(n-1)},\,\mathrm{r}_{4}:\!\!1b\!\!\to\!\!\!\mathit{p}x^{2(n-1)}d^{2(n-1)}\}\)  
\(\mathrm{R}_{3}=[\mathrm{r}_{5}:\!\!\mathit{c}\!\!\to\!\!\!\mathit{c}\!\! \mathit{c}\!\!\mathit{c}\!\!\to\!\!\!\mathit{c}\!\!\mathit{c}^{2},\,\mathrm{r }_{6}:\!\!\!\mathit{c}\!\!\to\!\!\mathit{d}\!\!\mathit{c}^{2}\!\mathit{r}^{2}, \,\mathrm{r}_{7}:\!\!\!\mathit{x}\!\!\to\!\!\!\mathit{y},\,\mathrm{r}_{8}:\! \!\!\mathit{p}\!\!\to\!\!\!\mathit{q}]\)  
\(\mathrm{R}_{4}=[\mathrm{r}_{9}:\!\!\!\mathit{z}\!\!\to\!\!\!\mathit{r}_{10}: \!\!\mathit{c}\!\!\mathit{y}]\)  
\(a,\,b,\,c,\,d,\,e,\,p,\,q,\,r,\,x,\,y,\,z,\,\,\lambda\) are objects in the system. \(n\) represents the maximum number of bits that can be converted, meaning that the P system can convert binary strings that do not exceed \(n\) bits. To visualize this specific P system used to convert binary to decimal, Figure 3 shows its architecture. \(\Pi_{2\_10}\) is used to convert binary numbers with no more than \(n\) digits into decimal numbers. Initially, \(a\) object is placed in membrane 1. Rule set R of \(\Pi_{2\_10}\) is divided into four subsets. \[\mathrm{R}=\mathrm{R}_{1}\cup\mathrm{R}_{2}\cup\mathrm{R}_{3}\cup\mathrm{R }_{4} \tag{5}\]  
where:  
\[\mathrm{R}_{1}=[\mathrm{r}_{1},\,\mathrm{r}_{2}],\,\mathrm{R}_{2}=[\mathrm{ r}_{3},\,\mathrm{r}_{4}],\,\mathrm{R}_{3}=[\mathrm{r}_{5},\,\mathrm{r}_{6},\, \mathrm{r}_{7},\,\mathrm{r}_{8}],\,\mathrm{R}_{4}=[\mathrm{r}_{9},\,\mathrm{ r}_{10},\,\mathrm{r}_{11},\,\mathrm{r}_{12}]\]  
\(\Pi_{2\_10}\) receives binary strings from the environment from low to high, each bit input is'0' or '1'. The rule in \(\mathrm{R}_{1}\) implements the conversion of the first bit of the input binary, which takes 1 time slice. Starting from the second bit of the input binary number, the rules in \(\mathrm{R}_{2}\), \(\mathrm{R}_{3}\), and \(\mathrm{R}_{4}\) are executed in turn every 3-time slices to complete the conversion of a binary number to a decimal number. When each bit of the binary number is converted, the final number of object \(r\) in membrane 1 is expressed as the converted decimal number. We assume that the binary string is \(\mathrm{A}_{\mathrm{m}}\mathrm{A}_{\mathrm{m}-1}\)...\(\mathrm{A}_{1}\), and the initial decimal number \(\left|\,r\,\right|=0\). \(\mathrm{A}_{\mathrm{m}}\mathrm{A}_{\mathrm{m}-1}\)...\(\mathrm{A}_{1}\) in \(\Pi_{2\_10}\) is converted to a decimal number as follows:  
(1) The system executes the first bit, \(\mathrm{A}_{1}\). The rules in \(\mathrm{R}_{1}\) will be selected for execution. After the rules in \(\mathrm{R}_{1}\) are executed, the current decimal number \(\left|\,r\,\right|\) is equal to the original number \(\left|\,r\,\right|\) plus the number of objects \(r\). If \(\mathrm{A}_{1}\) is '0', then \(\mathrm{r}_{1}\) is applied and produces objects \(b\) and \(e\), keeping \(\left|\,r\,\right|=0\) unchanged. If \(\mathrm{A}_{1}\) is '1', \(\mathrm{r}_{2}\) is applied and produces objects \(b\), \(e\), and \(r\), making \(\left|\,r\,\right|=1\). Figure 3: P system for binary to decimal. (2) The system executes other bits \(\rm A_{s}\) (\(1<s\leq m\)), including the following two cases:  
Case 1: \(\rm A_{s}\) is '0' The rules in R are executed as follows:  
1 Rule \(\rm r_{3}\) in \(\rm R_{2}\) executes the consumption object \(b\) to generate object \(p\), \(2^{n-1}\) objects \(x\), and object \(c\). (2) Rules \(\rm r_{5}\), \(\rm r_{7}\) and \(\rm r_{8}\) in \(\rm R_{4}\) will be in parallel.