With the semantic Web relying on ontologies to establish online machine- interpretable information, the Internet is growing into a semantically aware computing paradigm that facilitates Web entities' discovery of the knowledge and resources they need. Ambient intelligence aims to enable smart interaction beyond the Internet by embedding intelligence into our environment to unobtrusively support users' daily activities. To accomplish these goals, ontologies and semantic awareness are crucial for better understanding a user's context. While interest in the Semantic Web has spurred the development of large-scale semantic grid architectures, expanding the Semantic Web to the other side of the computing spectrum is a complex undertaking. The techniques and tools that support the semantic Web aren't designed to deal with the resource-constrained devices with which people frequently interact in an ambient-intelligence environment. To counter this disadvantage, we developed a coding scheme for ontologies that embeds semantic awareness in devices with limited memory and processing capabilities, such as sensory nodes and smart phones. This scheme provides a compact representation of an ontology and is enhanced with an efficient and effective semantic-matching algorithm.