A chemosensor consisting of an L-histidine covalently linked to an anthracene unit, L, has been synthesized, and its sensing behavior toward pH values and metal ions has been investigated by fluorescence and absorption spectroscopy. In aqueous solution, compound L may serve as an "off-on-off" fluorescence switch over 4.0 pH units. At neutral pH, the fluorescence intensities of L are enhanced by addition of Zn2+ and Cd2+ and quenched by metal ions such as Cu2+, Ni2+, CO2+, Hg2+, and Pb2+. Furthermore, the binding constants for L with Zn2+, Cu2+, Ni2+, CO2+, and Hg2+, respectively, are also determined by fluorescence titrations. On the other hand, compound L displays a drastic decrease in absorbance selectively with Hg2+ over other metal ions. On the basis of the above results, several logic gates (XNOR, OR, NOR, INHIBIT) and a half-subtractor have been achieved at the molecular level by changing the initial states of system L and chemical inputs.