Implementing the Trinary routines.