## 3 Encoder and Comparator  
The operation principle of the all-optical encoder and comparator using a CR-SOA-MZI relies on designing, executing, and combining five essential logic operations--\(\overline{\mathrm{A}}\)B, \(\overline{\mathrm{A}}\)B, AB (AND), \(\overline{\mathrm{A}}\)\(\overline{\mathrm{B}}\) (NOR), and AB + \(\overline{\mathrm{A}}\)\(\overline{\mathrm{B}}\) (XNOR)--using four CR-SOA-MZIs, as shown in Figure 2. The system involves three inputs: signals A, B, and a continuous wave (CW), injected into the CR-SOA-MZIs to achieve the desired logic functions. The wavelengths for signals A, B, and CW are 1550.7 nm, 1549.3 nm, and 1551.3 nm, respectively [25]. The CW signal plays a crucial role by providing a constant reference power level, which enables efficient cross-gain modulation (XGM) effects for the logic operations. In the encoder, each of the logic outputs corresponds to a different input condition: \(\overline{\mathrm{A}}\)B, \(\overline{\mathrm{A}}\)\(\overline{\mathrm{B}}\), AB, and \(\overline{\mathrm{A}}\)\(\overline{\mathrm{B}}\). The CR-SOA-MZIs perform the logic operations for these outputs. In the CR-SOA-MZII, the \(\overline{\mathrm{A}}\)B operation is realized at wavelength \(\lambda_{\mathrm{B}}\), with the optical power of signal A being significantly larger than signal B, aided by the CW signal at \(\lambda_{\mathrm{CW}}\), optimizing the XGM effect. Similarly, the CR-SOA-MZI2 performs the \(\overline{\mathrm{A}}\)\(\overline{\mathrm{B}}\) operation, where signal B holds higher optical power than A, and the CW signal further enhances the XGM effect. The AND (AB) operation is realized in the CR-SOA-MZI3, where the combined signals A, B, and CW generate the output at wavelength \(\lambda\)B. The NOR operation (\(\overline{\mathrm{A}}\)\(\overline{\mathrm{B}}\)) is executed in the CR-SOA-MZI4, where an AND operation between \(\overline{\mathrm{A}}\)\(\overline{\mathrm{B}}\) is carried out, supported by the CW signal and the XGM effect. Lastly, the XNOR gate (AB + \(\overline{\mathrm{A}}\)\(\overline{\mathrm{B}}\)) is achieved by combining the outputs of the AND and NOR gates, producing the logic function AB + \(\overline{\mathrm{A}}\)\(\overline{\mathrm{B}}\). For the comparator, the system provides three outputs to represent the results of comparing signals A and B. The A < B output is generated when A is bit \"0\" and B is bit \"1\", corresponding to the AB operation. When both A and B are either \"0\" or \"1\", the A = B output is bit \"1\", represented by \(\overline{\mathrm{A}}\)\(\overline{\mathrm{B}}\) or XNOR logic. Finally, when A is bit \"1\" and B is bit \"0\", the A > B output is activated, represented by the AB operation. To manage the input signals effectively, 3 dB optical couplers (OCs) distribute the A, B, and CW signals to the respective CR-SOA-MZIs, ensuring optimal power levels. Wavelength-selective couplers (WSCs) direct the signals to the correct MZIs based on their wavelengths, facilitating each logic function at its designated wavelength. Optical bandpass filters (OBPFs) at the output of each CR-SOA-MZI ensure that only the desired logic gate outputs are selected, eliminating unwanted signals and preserving high signal integrity. The combination of OCs, WSCs, and OBPFs ensures efficient generation and extraction of optical logic operations, providing a robust solution for high-speed all-optical digital encoders and comparators, making it a promising approach for future optical computing and photonic logic circuits. The truth table for both the encoder and comparator are shown in Table 2, which clarifies the logic outputs corresponding to various input combinations.